Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Assignment : OOP
Section : BSCS(H)
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:-
NAME :Mubarik
ROLL NO :349
AGE :19
--------------------------------
PROGRAM:-
#include<iostream>
struct st_data
string n;
int age;
int rol;
};
int main()
st_data s1;
s1.n= "Mubarik";
s1.rol=349;
s1.age=19;
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
19
19
18
19
22
333
349
347
348
345
349|MUBARIK|19
347|QADIR|18
348|SHAHRAM|19
345|SAIM|22
PROGRAM
#include<iostream>
struct st_data
string n[5];
int age[5];
int rol[5];
};
int main()
for(int i=0;i<5;i++)
{
cin>>name.n[i];
for(int i=0;i<5;i++)
cin>>age.age[i];
for(int i=0;i<5;i++)
cin>>roll.rol[i];
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:-
12
feet4inches8
PROGRAM
#include<iostream>
struct dis
float feet;
float inch;
};
int main()
dis d1,d2,d3;
cout<<"Enter first user distance \n";
cin>>d1.feet;
cin>>d1.inch;
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:-
ali
ENTER ROLL NO
40
50
60
jan
ENTER ROLL NO
60
70
80
ENTER STUDENT NAME
jam
ENTER ROLL NO
50
60
40
joli
ENTER ROLL NO
50
55
66
sam
ENTER ROLL NO
55
44
77
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:-
Name : jam
Roll no : 2
Age : 11
Address : karachi
--------------------------------
PROGRAM
#include<iostream>
struct student{
char name[10];
int rollno,age;
string adress;
};
void even(void);
student s[12];
int main()
cout<<"\nName :";
cin>>s[i].name;
cin>>s[i].rollno;
cout<<"\nAddress. :";
cin>>s[i].adress;
agee:
cin>>s[i].age;
cout<<endl;
if(s[i].age<11 || s[i].age>14)
goto agee;
system("pause");system("cls");
even();
void even(void)
{
int count=0;
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)
}
Q:5B: Output:-
Name : mubarik
Roll no : 2
Age : 11
Address : lahore
--------------------------------
PROGRAM
#include<iostream>
struct student{
char name[10];
int rollno,age;
string adress;
};
void rolno(void);
student s[12];
int main()
cout<<"\nName :";
cin>>s[i].name;
cin>>s[i].rollno;
cout<<"\nAddress :";
cin>>s[i].adress;
agee:
cin>>s[i].age;
cout<<endl;
if(s[i].age<11 || s[i].age>14)
goto agee;
system("pause");system("cls");
rolno();
void rolno(void)
int count=0,choice;
cout<<"\nEnter a Roll No. :";
cin>>choice;
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)
}
Q 6A: OUTPUT:-
No Customer
--------------------------------
PROGRAM
#include<iostream>
struct cust{
char name[10];
int acc_no,blnc;
};
void les(void);
cust s[12];
int main()
cout<<"\nName : ";
cin>>s[i].name;
cin>>s[i].acc_no;
cout<<"\nBalance : $";
cin>>s[i].blnc;
cout<<endl;
system("pause");system("cls");
les();
void les(void)
int count=0;
if(s[i].blnc<200)
cout<<"\nName : "<<s[i].name;
cout<<"\nBalance : $"<<s[i].blnc<<endl<<endl;
count++;
if(count==0)
}}