Computer Science, asked by sp20bscs0055, 3 months ago

Create a class 'Student' with three data members which are name, age and address.
The constructor of the class assigns default values name as "unknown", age as '0'
and address as "not available". It has two members with the same name 'setInfo()'.
First method has two parameters for name and age and assigns the same whereas the
second method takes has three parameters which are assigned to name, age and
address respectively.
Print the name, age and address of 5 students.

Answers

Answered by nbcarpool
0

Answer:

#include<iostream.h>

#include<conio.h>

#include<string.h>

class student

{

public: char name[10];

int age;

char address[20];

student(char n[10]="unknown",int ag=0,char a[20]="not availabe")

{

strcpy(name,n);

age=ag;

strcpy(address,a);

}

void display()

{

cout<<"\nName="<<name;

cout<<"\nAge="<<age;

cout<<"\nAddress="<<address;

}

};

void main()

{

student s1("Nils",29);

student s2("John",30,"USA");

student s3("Reeta",30,"USA");

students s4("Paul",30,"Ind");

students s5("Henry",30,"USA");

clrscr();

s1.display();

s2.display();

s3.display();

s4.display();

s5.display();

getch();

}

Explanation:

Similar questions