Question

Exercise #6: ------------ - Define a struct of your own that uses several different data types...

 Exercise #6:
  ------------
  - Define a struct of your own that uses several 
    different data types for the members. {At least 3.}
  - Create a structure of that type and:
    - place values into it's members
    - print the values of each member in the 
      structure
  - Write a display function that displays the contents of 
    your struct type     
0 0
Add a comment Improve this question Transcribed image text
Answer #1


#include <iostream>

using namespace std;
struct student{
char name[100];
int id;
float gpa;
  
};
// method which displays the student data
void display(student &s1){
cout<<"Student Data :\n";
cout<<"Name : "<<s1.name<<endl;
cout<<"Id : "<<s1.id<<endl;
cout<<"Gpa : "<<s1.gpa<<endl;
  
  
}
int main()
{
// creating and initializing the student struct
student s1= {"student1",123,8.5};
cout<<"Name : "<<s1.name<<endl;
cout<<"Id : "<<s1.id<<endl;
cout<<"Gpa : "<<s1.gpa<<endl;
display(s1);
return 0;
}

Note: Comment here for futher discussion if you face any issue

Add a comment
Know the answer?
Add Answer to:
Exercise #6: ------------ - Define a struct of your own that uses several different data types...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a c program of your choosing that follows the specifications below: Define a struct with...

    Create a c program of your choosing that follows the specifications below: Define a struct with 4 or more members. The struct must be different from the ones used in class (20 points) Declare an array of your struct using a size of 10 or more (20 points) Load the data for each element in your array from a text file (20 points) Display the data in your array in the terminal (20 points) Provide brief comments for every line...

  • Write three object-oriented classes to simulate your own kind of team in which a senior member...

    Write three object-oriented classes to simulate your own kind of team in which a senior member type can give orders to a junior member type object, but both senior and junior members are team members. So, there is a general team member type, but also two specific types that inherit from that general type: one senior and one junior. Write a Python object-oriented class definition that is a generic member of your team. For this writeup we call it X....

  • Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type...

    Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type int Name of type String Balance of type float Public members void Init) method to enter the values of data members void Show) method to display the values of data members void Deposit(int Amt) method to increase Balance by Amt void Withdraw(int Amt) method to reduce Balance by Amt (only if required balance exists in account) float RBalance() member function that returns the value...

  • in C language we need to find the following : EXERCISE 3: 1. Write the definition...

    in C language we need to find the following : EXERCISE 3: 1. Write the definition of a structure named employee that contains character array members for an employee's first and last names, an int member for the employee's age, a char member that contains 'M' or 'F' for the employee's gender, and a double member for the employee's hourly salary. 2. Using the above mentioned definition, write a C program that asks a user to enter the values of...

  • Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the c...

    C++ Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...

  • Define a class named COMPLEX for complex numbers, which has two private data members of type...

    Define a class named COMPLEX for complex numbers, which has two private data members of type double (named real and imaginary) and the following public methods: 1- A default constructor which initializes the data members real and imaginary to zeros. 2- A constructor which takes two parameters of type double for initializing the data members real and imaginary. 3- A function "set" which takes two parameters of type double for changing the values of the data members real and imaginary....

  • Using C++: 1. Array and Struct in Card applications: In card game design, card suit and...

    Using C++: 1. Array and Struct in Card applications: In card game design, card suit and face values can be defined with enumeration values. Declare suit values - – hearts, clubs, diamonds, spades using enum, declare face values of 2 – 10, Jack, Queen, King, Ace using enum Declare a structure called Card, and it includes two data members, whose data types are the above two defined enumerations suit and face typedef an array called Deck, and it includes all...

  • C++ visual studio program...Write your own version of a class template that will create a dynamic...

    C++ visual studio program...Write your own version of a class template that will create a dynamic stack of any data type. The pop function must return a bool; it should return a false if it was not able to pop an item off the stack. Otherwise it returns true. The parameter to the pop function is passed by reference and should be the item on the list if it was able to pop something. Create a driver program (main) that...

  • Q1)In your own words, define and briefly explain Data Communications. Also, name the five main components...

    Q1)In your own words, define and briefly explain Data Communications. Also, name the five main components of Data Communications. Q2)In your own words, write a short note about the TCP/IP PROTOCOL SUITE and what is the difference between TCP/IP and OSI Model? Q3)Noise is one of the causes of transmission impairment. Different types of noise can affect the transmission of the signals. Briefly List and define TWO of those types in your own words. Q4)Using your own words, explain the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT