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.
#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;
}
}
Comments
Leave a comment