Id Name Gender Level 11501 Arwa Said F Foundation • Create a function to read the data of structure via the keyboard • Create a second function to print all structure details. • Call both functions from the main()
c++
In the solution of given problem, we use call by reference method to pass struct variable into read() function. After that, we call display function to display all the information read through read() function.
C++ code:
#include<iostream>
using namespace std;
struct Student
{
string Id;
string Name;
char Gender;
string Level;
};
void read(Student& S) // use reference method to pass arguments
{
cout<<"Enter Student Id: ";
cin>>S.Id;
cout<<"Enter Stuent Name: ";
getline(cin>> std::ws, S.Name);
cout<<"Enter Stuent Gender: ";
cin>>S.Gender;
cout<<"Enter Stuent Level: ";
cin>>S.Level;
}
void display(Student S) // function to print information
{
cout<<"Student Id: "<<S.Id<<endl;
cout<<"Student Name: "<<S.Name<<endl;
cout<<"Student Gender: "<<S.Gender<<endl;
cout<<"Student Level: "<<S.Level<<endl;
}
int main()
{
Student std;
read(std); // read function call
cout<<"\n\nDisplay Information: "<<endl;
display(std); // display function call
}
Step by step
Solved in 2 steps with 1 images