Write a C++ that prints your name ,your index number filed and study of the university name to the screen
#include<iostream>
#include<string>
using namespace std;
class Student
{
string name;
int index;
string studOfUniv;
public:
Student(){}
Student(string _name, int _index, string _studOfUniv)
:name(_name),index(_index), studOfUniv(_studOfUniv){}
void AddInfo()
{
cout<<"\nPlease, enter a name of student: ";
cin>>name;
cout<<"Please, enter an index of student: ";
cin>>index;
cout<<"Please, enter study of the university name: ";
cin.ignore(256,'\n');
getline(cin,studOfUniv,'\n');
}
void Display()
{
cout<<"\nInfo about student:"
<<"\nThe name of student is\t\t\t"<<name
<<"\nThe index of student is\t\t\t"<<index
<<"\nThe study of the university name is\t"<<studOfUniv;
}
};
int main()
{
Student a("John",123456,"Learning English");
a.Display();
cout<<endl;
Student b;
b.AddInfo();
b.Display();
}
Comments
Leave a comment