Answer to Question #213203 in C++ for Hemambar

Question #213203

Wrtie a program to create a class STUD with data members first_name, last_name, DOB.

Create an array of ‘n’ students by reading last_name, first_name and DOB into a single string

separated by commas and then extract each component into separate data members. Display the

student data in the form of a table with headers.


1
Expert's answer
2021-07-22T18:38:13-0400
#include<iostream>
#include<vector>
#include<string>
using namespace std;
class  STUD{
	private:
	string first_name, last_name, DOB;
	public:
		STUD(){
			
		}
		STUD(string f, string l, string d): first_name(f), last_name(l), DOB(d) {};
		string getFirst(){
			return first_name;
		}
		string getLast(){
		return last_name;
		}
		string getDOB(){
			return DOB;
		}
		int NumberOfStudents(){
			int n;
			cout<<"Enter the number of students\n";
			cin>>n;
			return n;
		}
};


int main(){
	STUD d;
int n= 	d.NumberOfStudents();
string arr[1000];
cout<<n<<"\n";
for(int i=0; i<n; i++){
		string first, last, DOB;
	cout<<"Enter the first name\n";
	cin>>first;
	cout<<"Enter the last name\n";
	cin>>last;
	cout<<"Enter the DOB\n";
	cin>>DOB;
	STUD st(first,last,DOB );
	string details = st.getFirst() + ", \t\t" +st.getLast()+ ", \t\t"+st.getDOB();
	//cout<<details;
	arr[i] = details;




}
cout<<"The table for the students is:   \n";
cout<<"First Name, \t"<<"Last Name, \t"<<"Date Of Birth\n";//The header of the table
for(int i=0; i<n; i++){
	cout<<arr[i]<<endl;
}


	
}

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
APPROVED BY CLIENTS