Está en la página 1de 20

Name : MUBARIK AKBAR

Assignment : OOP

Section : BSCS(H)

Submitted to: Ms. SADIA ZAFAR

Roll No : 349
PROGRAMS

Q#1: Write a program that store and print roll no ,name, age and marks of a
student by using structure.

OUT PUT:-

THA DATA OF A STUDENT IS :-

NAME :Mubarik

ROLL NO :349

AGE :19

--------------------------------

Process exited after 0.1642 seconds with return value 0

Press any key to continue . . .

PROGRAM:-
#include<iostream>

using namespace std;

struct st_data

string n;

int age;

int rol;

};

int main()

st_data s1;

s1.n= "Mubarik";
s1.rol=349;

s1.age=19;

cout<<"\n THA DATA OF A STUDENT IS :-";

cout<<"\nNAME :"<<s1.n;

cout<<"\nROLL NO :"<<s1.rol;

cout<<"\nAGE :"<<s1.age;

return 0;}

Q NO#2: Write a program that store and print roll no ,name, age and marks
of 5 student and display detail from roll no 2:-

Output:-
Enter name of students

ALI

MUBARIK

QADIR

SHAHRAM

SAIM

Enter age of students

19

19

18

19

22

Enter roll no of students

333

349
347

348

345

The record of students

349|MUBARIK|19

347|QADIR|18

348|SHAHRAM|19

345|SAIM|22

PROGRAM

#include<iostream>

using namespace std;

struct st_data

string n[5];

int age[5];

int rol[5];

};

int main()

st_data name , age , roll;

cout<<"Enter name of students\n";

for(int i=0;i<5;i++)

{
cin>>name.n[i];

cout<<"Enter age of students\n";

for(int i=0;i<5;i++)

cin>>age.age[i];

cout<<"Enter roll no of students\n";

for(int i=0;i<5;i++)

cin>>roll.rol[i];

cout<<"The record of students\n";

for(int i=1;i<5;i++)

cout<<roll.rol[i]<<"|"<<name.n[i]<<"|"<<age.age[i]<<endl;

}
Q NO#3 : Write a program to add two distances in feet and inch by using
structure :-

Output:-

Enter first user distance

12

Enter second user distance

feet4inches8

PROGRAM

#include<iostream>

using namespace std;

struct dis

float feet;

float inch;

};

int main()

dis d1,d2,d3;
cout<<"Enter first user distance \n";

cin>>d1.feet;

cin>>d1.inch;

cout<<"Enter second user distance \n";

cin>>d2.feet;

cin>>d2.inch;

d3.inch=d1.inch+d2.inch;

d3.feet=d1.feet+d2.feet;

if(d3.inch>=12)

d3.inch-=12;

d3.feet=d3.feet+1;

cout<<"feet"<<d3.feet<<"inches"<<d3.inch;

}
Q4 : Write a program that take marks of 5 student and calculate persuntage:-

Output:-

ENTER STUDENT NAME

ali

ENTER ROLL NO

ENTER STUDENT MARKS

40

50

60

ENTER STUDENT NAME

jan

ENTER ROLL NO

ENTER STUDENT MARKS

60

70

80
ENTER STUDENT NAME

jam

ENTER ROLL NO

ENTER STUDENT MARKS

50

60

40

ENTER STUDENT NAME

joli

ENTER ROLL NO

ENTER STUDENT MARKS

50

55

66

ENTER STUDENT NAME

sam
ENTER ROLL NO

ENTER STUDENT MARKS

55

44

77

THE RESULT OF STUDENT:-

NAME ali

ROLL NO 1

MARKS IN CHIMESTRY 13

MARKS IN PHYSICS 16

MARKS IN MATH 20

NAME jan

ROLL NO 2

MARKS IN CHIMESTRY 20

MARKS IN PHYSICS 23
MARKS IN MATH 26

NAME jam

ROLL NO 3

MARKS IN CHIMESTRY 16

MARKS IN PHYSICS 20

MARKS IN MATH 13

NAME joli

ROLL NO 3

MARKS IN CHIMESTRY 16

MARKS IN PHYSICS 18

MARKS IN MATH 22

NAME sam

ROLL NO 4

MARKS IN CHIMESTRY 18

MARKS IN PHYSICS 14

MARKS IN MATH 25
Q:5 A program that display roll no ,name,age and address of student:-

OUTPUT:-

Students With Even Roll No.

Name : jam

Roll no : 2

Age : 11

Address : karachi

--------------------------------

PROGRAM

#include<iostream>

using namespace std;

struct student{

char name[10];

int rollno,age;

string adress;

};

void even(void);

student s[12];

int main()

for(int i=0; i<4; i++)


{

cout<<"\nEnter Data of Student number "<<i+1;

cout<<"\nName :";

cin>>s[i].name;

cout<<"\nRoll No. :";

cin>>s[i].rollno;

cout<<"\nAddress. :";

cin>>s[i].adress;

cout<<"\nAge (Between 11 to 14) :";

agee:

cin>>s[i].age;

cout<<endl;

if(s[i].age<11 || s[i].age>14)

cout<<"\nNot valid date \n";

cout<<"\nEnter again :";

goto agee;

system("pause");system("cls");

even();

void even(void)
{

int count=0;

cout<<"\nStudents With Even Roll No.\n";

for(int i=0; i<4; i++)

if(s[i].rollno%2==0)

cout<<"\nName : "<<s[i].name;

cout<<"\nRoll no : "<<s[i].rollno;

cout<<"\nAge : "<<s[i].age<<endl<<endl;

cout<<"\nAddress : "<<s[i].adress;

count++;

if(count==0)

cout<<"\nNo Student ";

}
Q:5B: Output:-

Enter a Roll No. :2

Name : mubarik

Roll no : 2

Age : 11

Address : lahore

--------------------------------
PROGRAM

#include<iostream>

using namespace std;

struct student{

char name[10];

int rollno,age;

string adress;

};

void rolno(void);

student s[12];

int main()

for(int i=0; i<2; i++)


{

cout<<"\nEnter Data of Student number "<<i+1;

cout<<"\nName :";

cin>>s[i].name;

cout<<"\nRoll No. :";

cin>>s[i].rollno;

cout<<"\nAddress :";

cin>>s[i].adress;

cout<<"\nAge (Between 11 to 14) :";

agee:

cin>>s[i].age;

cout<<endl;

if(s[i].age<11 || s[i].age>14)

cout<<"\nNot valid date \n";

cout<<"\nEnter again :";

goto agee;

system("pause");system("cls");

rolno();

void rolno(void)

int count=0,choice;
cout<<"\nEnter a Roll No. :";

cin>>choice;

for(int i=0; i<2; i++)

if(choice==s[i].rollno)

cout<<"\nName : "<<s[i].name;

cout<<"\nRoll no : "<<s[i].rollno;

cout<<"\nAge : "<<s[i].age;

cout<<"\nAddress : "<<s[i].adress<<endl<<endl;

count++;

break;

if(count==0)

cout<<"\nNo Student ";

}
Q 6A: OUTPUT:-

Customers With Balance Less Than $200 :

No Customer

--------------------------------

Process exited after 28.85 seconds with return value 0

Press any key to continue . . .

PROGRAM

#include<iostream>

using namespace std;

struct cust{

char name[10];

int acc_no,blnc;

};

void les(void);

cust s[12];

int main()

for(int i=0; i<2; i++)

cout<<"\nEnter Data of Customer number "<<i+1;

cout<<"\nName : ";

cin>>s[i].name;

cout<<"\nAccount No. : ";

cin>>s[i].acc_no;
cout<<"\nBalance : $";

cin>>s[i].blnc;

cout<<endl;

system("pause");system("cls");

les();

void les(void)

int count=0;

cout<<"\nCustomers With Balance Less Than $200 :";

for(int i=0; i<2; i++)

if(s[i].blnc<200)

cout<<"\nName : "<<s[i].name;

cout<<"\nAccount NO. : "<<s[i].acc_no;

cout<<"\nBalance : $"<<s[i].blnc<<endl<<endl;

count++;

if(count==0)

cout<<"\nNo Customer ";

}}

También podría gustarte