CS304 Lecture 12 Programs

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Lecture No.

1 OOP Programs

// Task 1: Array of Object (Method 1)


#include<iostream>
#include<conio.h>
using namespace std;
class Student
{
int RollNo;
string Name;
public:
Student(int r,string n)
{
RollNo = r;
Name = n;
}
void getData()
{
cout<<"***** Student Record *****";
cout<<"\n\nRoll No.: "<<RollNo;
cout<<"\n\nName: "<<Name<<"\n\n\n";
}
};
main()
{
Student s[5] = {
Student(100,"Ali"),
Student(101,"Khizar"),
Student(102,"KST"),
Student(103,"Learning"),
Student(104,"Numan")
};
for(int i=0; i<=4; i++)
{
s[i].getData();
}
getch();
return 0;
}

// Task 2: Array of Object (Method 2)


#include<iostream>
#include<conio.h>
using namespace std;
class Student
{
int RollNo;
string Name;
public:
Student()
{
RollNo = 0;
Name = "";
}
void setData()
{
cout<<"***** Take Student Record *****";
cout<<"\n\nEnter Roll No.: ";
cin>>RollNo;
cout<<"\nEnter Name: ";
cin>>Name;
cout<<"\n\n\n";
}
void getData()
{
cout<<"***** Student Record *****";
cout<<"\n\nRoll No.: "<<RollNo;
cout<<"\n\nName: "<<Name<<"\n\n\n";
}
};
main()
{
Student s[5];
for(int i=0; i<=4; i++)
{
s[i].setData();
}
for(int i=0; i<=4; i++)
{
s[i].getData();
}
getch();
return 0;
}

You might also like