Computer Science, asked by Asiyah4954, 1 year ago

Design a class student representing roll no, name, height, weight. Include a default constructor to assign values to the above members, a read() member function to get values to the above members and a display() member function to display the same.
Create two objects s1 ans s2. Call the member function read() only with s1 and display() with s1 and s2. Default Values are as follows:
name=Nikhil
rollno=20;
height=165.5;
weight=58.2;
please do it in c++
input sample: Richard 95 168.5 65.3
Output sample: Richard 95 168.5 65.3
Nikhil 20 165.5 58.2

Answers

Answered by qwtiger
1

Answer:

class Student

{

 int Roll;

char name[25];

float weight;

float height;

public:

Student()          

{

  strcpy(Name,"Nikhil");

Roll = 20;

        height = 165.5;

       weight = 58.2;

} ;

void read (){

   cout << "Enter name: " ;

   cin >> name;

   cout << "Enter roll number: ";

   cin >> rollNo;

   cout << "Enter height: ";

   cin >> height;

cout << "Enter weight: ";

   cin >> weight;

}

void display()

{

cout<<"\n\tName : "<<Name;

cout<<"\n\tRoll : "<<Roll;

cout<<"\n\tHeight : "<<height;

cout<<"\n\tWeight : "<<weight;

}  

void main()

{  

    Student s1, s2;

   s1.read();

   s2.read();

   s2.display();

}

Similar questions