0% found this document useful (0 votes)
153 views

Thapar Object Oriented Programming Assignment Lab 1

The document contains 6 C++ programs that demonstrate basic concepts like input/output, namespaces, structures, and classes. Each program shows how to define and use the respective concept through simple examples like printing text, defining namespaces for functions, creating structures to store student data, and defining a class to represent students.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views

Thapar Object Oriented Programming Assignment Lab 1

The document contains 6 C++ programs that demonstrate basic concepts like input/output, namespaces, structures, and classes. Each program shows how to define and use the respective concept through simple examples like printing text, defining namespaces for functions, creating structures to store student data, and defining a class to represent students.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT-1

1.
#include<iostream>

Using namespace std;

int main()

cout<<"Hello World";

return 0;

2.
#include<iostream>

using namespace std;

int main()

cout<<"hello \t world"<<endl;

cout<<"hello"<<endl<<"world"<<endl;

cout<<"\a";

cout<<"hello world \r";

return 0;

3. #include <iostream>
using namespace std;

namespace first_space

void func()

cout << "Inside first_space" << endl;

namespace second_space

void func()
{

cout << "Inside second_space" << endl;

int main ()

first_space::func();

second_space::func();

return 0;

4.
#include<iostream>

using namespace std;

struct student

char name[40];

int roll;

float marks;

void setStudentData()

cout<<"enter name of student";

cin>>name;

cout<<"enter roll number of student";

cin>>roll;

cout<<"enter marks of student";

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++)

struct student s1;

s1.setStudentData();

s1.getStudentData();

return 0;

5.
#include<iostream>

using namespace std;

struct student

private:

char name[40];

int roll;

float marks;

public:

void setStudentData()

cout<<"enter name of student";

cin>>name;

cout<<"enter roll number of student";

cin>>roll;

cout<<"enter marks of student";

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++)

struct student s1;

s1.setStudentData();

s1.getStudentData();

return 0;

6.
#include<iostream>

using namespace std;

class student

public:

char name[40];

int roll;

float marks;

void setStudentData()

cout<<"enter name of student";

cin>>name;

cout<<"enter roll number of student";

cin>>roll;

cout<<"enter marks of student";

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;

Name – Prabhdeep singh


Class – 1EM2
Roll Number - 102119034

You might also like