Objective:
Write a program that uses a structure named Student to store the following information about a student:
• Student ID
• Student Name
• Major
• Year Passed
The program should create two Student variables, store values in their members, and pass each one, in turn, to a function that displays the information about the student in a clearlv formatted
manner.
#include <iostream>
#include <string>
using namespace std;
struct Student{
int ID;
string Name;
string Major;
int YearPassed;
};
void display(Student student){
cout<<"Student ID: "<<student.ID<<"\n";
cout<<"Student Name: "<<student.Name<<"\n";
cout<<"Student Major: "<<student.Major<<"\n";
cout<<"Student year passed: "<<student.YearPassed<<"\n\n";
}
int main() {
Student student1;
student1.ID=546;
student1.Name="Mike";
student1.Major="Major";
student1.YearPassed=3;
Student student2;
student2.ID=789;
student2.Name="Mary";
student2.Major="Major 5";
student2.YearPassed=2;
display(student1);
display(student2);
system("pause");
return 0;
}
Comments
Leave a comment