Computer Science, asked by ntoct17, 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;

Language:: c++

INPUT
Richard 95 168.5 65.3
OUTPUT
Richard 95 168.5 65.3
Nikhil 20 165.5 58.2

Answers

Answered by Anonymous
2

Answer:

class Student{

int roll_no;

char student_name[25];

float student_weight, student_height;

public:

Student()        //default constrctor   

{  strcpy( student_name,"Nikhil");

roll_no = 20;

student_height= 165.5;

student_weight= 58.2;

} ;

void read () // to read the user given input

{  cout << "Enter name of the student: " ;

 cin >>  student_name;

 cout << "Enter roll number: ";

 cin >> roll_no;

cout << "Enter height of the student: ";

cin >>  student_height;

cout << "Enter weight of the student: ";

cin >> student_weight;

}

void display() // this method will be called to display the values

{

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

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

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

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

}  

void main() // main method to call the methods

{  

Student s1, s2;

s1.read();

s2.read();

s2.display();

}

Answered by markpeter1501
0

Answer:

#include<iostream>

#include<string>

using namespace std;

class student{

   public :

   string name;

   int rollno;

   float height,weight;

   student(){

  name="Nikhil";

  rollno=20;

  height=165.5;

  weight=58.2;

}

void read(){

   cin>>name>>rollno>>height>>weight;

}

void display(){

   cout<<name<<" "<<rollno<<" "<<height<<" "<<weight<<endl;

}

};

int main(){

   student s1,s2;

   s1.read();

   s1.display();

   s2.display();

   return 0;

}

Explanation:

Similar questions