Answer to Question #240501 in C++ for siri

Question #240501

Create a class student which stores name, date-of-birth and date-of-joining of a student. The data members date-of-birth and date-of-joining should be the objects of another class called 'date'. Input the data for 10 students and display it.


1
Expert's answer
2021-09-22T06:28:58-0400
#include<iostream>
#include<bits/stdc++.h>
using namespace std;


class Student{
	string name;
	public:
		string dob;
		string doj;
		
		void input()
		{
			cout<<"Enter student name : ";
			string s;
			getline(cin,s);
			name = s;
			cout<<"Enter Date-of-Birth : ";
			getline(cin,dob);
			cout<<"Enter Date-of-Joining : ";
			getline(cin,doj);
		}
		
		void printName()
		{
			cout<<"Student name : "<<name<<endl;
		}
};




class Date: public Student{
	public:
		void print()
		{
			cout<<"Date-of-Birth : "<<dob<<endl;
			cout<<"Date-of-Joining : "<<doj<<endl;
		}
};


int main()
{
	int n;
	cout<<"Enter details of 10 students : "<<endl<<endl;
	Date d[10];
	
	for(int i=0; i<10; i++)
	{
		d[i].input();
		cout<<endl;
	}
	
	
	cout<<endl<<"Displaying details of students : "<<endl;
	cout<<"---------------------------------"<<endl<<endl;
	for(int i=0; i<10; i++)
	{
		d[i].printName();
		d[i].print();
		cout<<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