68.6k views
1 vote
Each student has a record on a file consisting of the following data: Student last name, Student ID (numeric), GPA (a decimal number), major (a 3 digit code). a. Define a structure that could be used to process this data record. b. Declare an instance of this structure. c. Write ONE cout statement to show the Student name on the screen. HTML EditorKeyboard Shortcuts

1 Answer

6 votes

Answer:

#include<iostream>

using namespace std;

struct student {

string name;

int id;

float gpa;

int major;

};

int main() {

student student1;

student1.name="Patil";

student1.id=1;

student1.gpa=9.80;

student1.major=123;

cout<<"First student last name: "<<student1.name;

}

Step-by-step explanation:

A struct is a container or data structure in C and C++ that holds data that describes or represents an object. It is defined with the struct keyword. Just like a class constructor method, the struct is called with the struct name and the instance name of the struct.

The student struct above is used to create an instance of students registered in a school. The first student struct instance is the 'student1'.

User Simon Peyou
by
5.2k points