Thapar Object Oriented Programming Assignment Lab 1
Thapar Object Oriented Programming Assignment Lab 1
Thapar Object Oriented Programming Assignment Lab 1
1.
#include<iostream>
int main()
cout<<"Hello World";
return 0;
2.
#include<iostream>
int main()
cout<<"hello \t world"<<endl;
cout<<"hello"<<endl<<"world"<<endl;
cout<<"\a";
return 0;
3. #include <iostream>
using namespace std;
namespace first_space
void func()
namespace second_space
void func()
{
int main ()
first_space::func();
second_space::func();
return 0;
4.
#include<iostream>
struct student
char name[40];
int roll;
float marks;
void setStudentData()
cin>>name;
cin>>roll;
cin>>marks;
void getStudentData()
cout<<"name:"<<name<<endl<<"roll number:"<<roll<<endl<<"marks:"<<marks<<endl;
};
int main()
{
int i;
student s[3];
for(i=0;i<3;i++)
s1.setStudentData();
s1.getStudentData();
return 0;
5.
#include<iostream>
struct student
private:
char name[40];
int roll;
float marks;
public:
void setStudentData()
cin>>name;
cin>>roll;
cin>>marks;
void getStudentData()
cout<<"name:"<<name<<endl<<"roll number:"<<roll<<endl<<"marks:"<<marks<<endl;
}
};
int main()
int i;
student s[3];
for(i=0;i<3;i++)
s1.setStudentData();
s1.getStudentData();
return 0;
6.
#include<iostream>
class student
public:
char name[40];
int roll;
float marks;
void setStudentData()
cin>>name;
cin>>roll;
cin>>marks;
void getStudentData()
{
cout<<"name:"<<name<<endl<<"roll number:"<<roll<<endl<<"marks:"<<marks<<endl;
};
int main()
int i;
student s[3];
for(i=0;i<3;i++)
student s1;
s1.setStudentData();
s1.getStudentData();
return 0;