Answer to Question #277933 in C++ for Bhagi

Question #277933

Write a C++ that prints your name ,your index number filed and study of the university name to the screen

1
Expert's answer
2021-12-10T06:38:56-0500
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog