Question

struct nameType { string first; string last; }; struct studentType { nameType name; double gpa; };...

struct nameType {

string first;

string last;

};

struct studentType {

nameType name;

double gpa;

};

a. Write a program that declares an array of the studentType structure, size 10, name of your choice, and includes the following:

• Write a void function to request user input into each of the members of the studentType structure array. Be sure to include proper user prompts. Assume the entire structure array is filled. Write the prototype and the function definition.

• Call the function from main.

• Write a void function to output the information in the studentType structure array. Write the prototype and the function definition.

• Call the function from main.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <cstring>

using namespace std;

struct nameType {

string first;

string last;

};

struct studentType {

nameType name;

double gpa;

};

int main(){

struct studentType stud[10];
int i;

cout << "enter Student details"<< endl;

for(i=0; i<10; i++){ //taking values from user

cout<<"First name\t";
cin >> stud[i].name.first;

cout<<"last name\t";
cin >> stud[i].name.last;


cout << "Enter GPA\t";
cin >> stud[i].gpa;
cout<<endl;
}

for(i=0; i<10; i++){ //printing values
cout << "Student firrst name \t "<<stud[i].name.first << endl;

cout << "Student last name \t "<<stud[i].name.last << endl;
cout << "Student GPA : \t" << stud[i].gpa<< endl;
}
return 0;

}

Add a comment
Know the answer?
Add Answer to:
struct nameType { string first; string last; }; struct studentType { nameType name; double gpa; };...
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
  • Consider the following statements: struct nameType { string first; string last; }; struct courseType { string...

    Consider the following statements: struct nameType { string first; string last; }; struct courseType { string name; int callNum; int credits; char grade; }; struct studentType { nameType name; double gpa; courseType course; }; studentType student; studentType classList[100]; courseType course; nameType name; Mark the following statements as valid or invalid. If a statement is invalid, explain why. student.course.callNum = "CSC230"; cin >> student.name; classList[0] = name; classList[1].gpa = 3.45; name = classList[15].name; student.name = name; cout << classList[10] << endl;...

  • Answer it by using c++ context. struct courseType struct studentType { { struct name Type {...

    Answer it by using c++ context. struct courseType struct studentType { { struct name Type { string first; string last; }; string name; int callNum; int credits; char grade; name Type name; double gpa; courseType course; }; student Type student; student Type classList[100]; course Type course; nameType name; Mark the following statements as valid or invalid. If a statement is invalid, explain why. a. student.name.last="Anderson"; b. classList[1].name = student; c. student.name = classList[10].name;

  • 1. 2. Given struct Sudent [ string firstName; string lastName double gpa, MovieData movie-new MovieData[10]: Write...

    1. 2. Given struct Sudent [ string firstName; string lastName double gpa, MovieData movie-new MovieData[10]: Write a statement that dynamically allocates an array to hold 100 students

  • I am struggling with a program in C++. it involves using a struct and a class...

    I am struggling with a program in C++. it involves using a struct and a class to create meal arrays from a user. I've written my main okay. but the functions in the class are giving me issues with constructors deconstructors. Instructions A restaurant in the Milky way galaxy called “Green Alien” has several meals available on their electronic menu. For each food item in each meal, the menu lists the calories per gram and the number of grams per...

  • Consider the Tollowing class declaration: class student record public: int age; string name; double gpa; }:...

    Consider the Tollowing class declaration: class student record public: int age; string name; double gpa; }: Implement a void function that initiatizes a dynamic array of student records with the data stored in the file "university body.txt". The function has three formal parameters: the dynamic array "S db, the count, and the capacity. Open and close an ifstream inside the function. Remember, you must allocate memory for the initial size of the dynamic array using "new" inside this function. If...

  • struct Item { string name; int quantity; float cost; }; const int MAX_SIZE = 50; class...

    struct Item { string name; int quantity; float cost; }; const int MAX_SIZE = 50; class ManageInventory { public: ManageInventory() : count{0}, p_pInventoryItems {new Item*[size]} { } ManageInventory(int size) : size{size}, count{0}, p_pInventoryItems {new Item*[size]} { } ~ManageInventory(); void addItem(string name, int quantity, float cost); private: int size {MAX_SIZE}; int count; Item ** p_pInventoryItems; }; Write the definition for addItem. Use the new operator to dynamically create instances of type Item. Store pointers to inventory items in the inventoryItems array....

  • 1. Create a file that contains 3 rows of data of the form: First Name Middle...

    1. Create a file that contains 3 rows of data of the form: First Name Middle Name Last Name Month Day Year Month Day Year GPA. This file represents student data consisting of first name, middle name, last name, registration month, registration day, registration year, birth month, birth day, birth year, current gpa. ...or you may download the data file inPut.txt. inPut.txt reads:​​​​​​​ Tsia Brian Smith 9 1 2013 2 27 1994 4.0 Harper Willis Smith 9 2 2013 9...

  • Define a class called Student with ID (string), name (string), units (int) and gpa (double). Define...

    Define a class called Student with ID (string), name (string), units (int) and gpa (double). Define a constructor with default values to initialize strings to NULL, unit to 0 and gpa to 0.0. Define a copy constructor to initialize class members to those of another Student passed to it as parameters. Overload the assignment operator (=) to assign one Student to another. Define a member function called read() for reading Student data from the user and a function called print()...

  • Declare a struct worker with the following attributes: char array first name string surname int age...

    Declare a struct worker with the following attributes: char array first name string surname int age double salary. then , declare a structure my worker which is of type worker. ( read carefully, don,t make a mistake! ) one line is needed for the answer. in c programming

  • A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double...

    A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double GPA(=(4.0*NumberOfAs+3.0*NumberOfBs+2.0*NumberOfCs+1.0*NumberOfDs)/( As+Bs+Cs+Ds+Fs)); Public data member, void setFirstName(string name); string getFirstName() const; void printFirstName() const; void getLastName(string name); string getLastName() const; void printLastName() const; void computeGPA(int NumberOfAs,int NumberOfBs,int NumberOfCs,int NumberOfDs,int NumberOfFs); double getGPA() const; double printGPA() const; A destructor and an explicit default constructor initializing GPA=0.0 and checking if GPA>=0.0 by try{}catch{}. Add member function, bool operator<(const Student); The comparison in this function based on...

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
ADVERTISEMENT