DO THIS PROGRAM AND TAKE PHOTOS OF CODES AND OUTPUT':
1.
Create a Class and initialize attribute of the following:
Class name: Student
Attribute: First Name
Last Name
Sex
Age
2.
From the created class, create 5 objects, and display it using
pretty table.
#include <iostream>
using namespace std;
class Student{
private:
string firstName;
string lastName;
string sex;
int age;
public:
Student(string f, string l, string s,int a){
firstName=f;
lastName=l;
sex=s;
age=a;
}
void display(){
cout<<"\n"<<firstName<<"\t"<<lastName<<"\t"<<sex<<"\t"<<age;
}
};
int main()
{
Student s1("Mary","Anne","Female",22);
Student s2("Moses","White","Male",30);
Student s3("Carol","David","Female",21);
Student s4("John","Smith","Male",24);
Student s5("Nana","Vennesa","Female",23);
cout<<"\n"<<"First Name\tLast Name\tSex\tAge";
s1.display();
s2.display();
s3.display();
s4.display();
s5.display();
return 0;
}
Comments
Leave a comment