STRUCTURE PROGRAMS
QUESTION NO 1
Write a program that declares a structure Student to
store Roll No (int), name (string) and marks of 05
subject (array of integer with const SIZE), average
(float) marks of a student. The program should define
a structure variable, inputs the values, finds the
average and then displays the student
values on the screen.
#include <iostream>
using namespace std;
const int SIZE=5;
struct Student
int marks[SIZE];
string name;
int roll_no;
float avg;
};
int main()
{
Student s;
cout<<"Enter Name"<<endl;
cin>>s.name;
cout<<"Enter Rol no "<<endl;
cin>>s.roll_no;
int sum=0;
for(int i=0;i<SIZE;i++)
cout<<"Enter marks of "<<i+1<<" Subject"<<endl;
cin>>s.marks[i];
sum=sum+s.marks[i];
s.avg=sum/SIZE;
cout<<"Name is : "<<s.name<<endl;
cout<<s.name<<" Average is "<<s.avg<<endl;
cout<<s.name<<" Your Roll no is : "<<s.roll_no<<endl;
for(int i=0;i<SIZE;i++)
cout<<"Marks of Subject-"<<i+1<<" is "<<s.marks[i]<<endl;
return 0;
QUESTION NO 1
#include <iostream>
using namespace std;
const int SIZE=5;
struct Struct
int no;
};
int main()
Struct s;
cout<<"Enter a number "<<endl;
cin>>s.no;
cout<<"No is : "<<s.no<<endl;
return 0;
QUESTION NO 2
#include <iostream>
using namespace std;
const int SIZE=5;
struct person
int id;
string name;
int age;
};
int main()
{
person p;
cout<<"Enter Name "<<endl;
cin>>p.name;
cout<<"Enter Age "<<endl;
cin>>p.age;
cout<<"Enter ID "<<endl;
cin>>p.id;
cout<<"Name is : "<<p.name<<endl;
cout<<p.name<<" your age is : "<<p.age<<endl;
cout<<p.name<<" your id is : "<<p.id<<endl;
return 0;
QUESTION NO 3
#include <iostream>
using namespace std;
const int SIZE=5;
struct Student
int roll_no;
int marks_e,marks_p,marks_c;
float avg;
};
int main()
int sum;
Student s;
cout<<"Enter Roll no "<<endl;
cin>>s.roll_no;
cout<<"Enter marks of English "<<endl;
cin>>s.marks_e;
cout<<"Enter marks of Physics "<<endl;
cin>>s.marks_p;
cout<<"Enter marks of Computer "<<endl;
cin>>s.marks_c;
sum=s.marks_e+s.marks_p+s.marks_c;
s.avg=sum/3.0f;
cout<<"Average is : "<<s.avg<<endl;
return 0;
QUESTION NO 4
#include <iostream>
using namespace std;
const int SIZE=5;
struct Computer
int id;
string name;
float price;
};
int main()
Computer c1,c2;
cout<<"Enter First Computer ID "<<endl;
cin>>c1.id;
cout<<"Enter First Computer name "<<endl;
cin>>c1.name;
cout<<"Enter First Computer price "<<endl;
cin>>c1.price;
cout<<"Enter Second Computer ID "<<endl;
cin>>c2.id;
cout<<"Enter Second Computer name "<<endl;
cin>>c2.name;
cout<<"Enter Second Computer price "<<endl;
cin>>c2.price;
if(c1.price>c2.price)
cout<<"Computer 1 is costly"<<endl;
cout<<"Computer id is : "<<c1.id<<endl;
cout<<"Computer name is : "<<c1.name<<endl;
cout<<"Computer price is : "<<c1.price<<endl;
else
cout<<"Computer 2 is costly"<<endl;
cout<<"Computer id is : "<<c2.id<<endl;
cout<<"Computer name is : "<<c2.name<<endl;
cout<<"Computer price is : "<<c2.price<<endl;
return 0;
}
QUESTION NO 5
#include <iostream>
using namespace std;
const int SIZE=5;
struct Employee
int no,hourly_pay;
string name;
int hours_worked;
int gross_pay;
};
int main()
Employee e;
cout<<"Enter Employee number "<<endl;
cin>>e.no;
cout<<"Enter Employee name "<<endl;
cin>>e.name;
cout<<"Enter hours worked "<<endl;
cin>>e.hours_worked;
cout<<"Enter hourly pay "<<endl;
cin>>e.hourly_pay;
e.gross_pay=e.hours_worked*e.hourly_pay;
cout<<"Employee number is : "<<e.no<<endl;
cout<<"Employee name is : "<<e.name<<endl;
cout<<"hours worked is : "<<e.hours_worked<<endl;
cout<<"hourly pay is : "<<e.hourly_pay<<endl;
cout<<"Gross pay is : "<<e.gross_pay<<endl;
return 0;
}
QUESTION NO 6
#include <iostream>
using namespace std;
const int SIZE=5;
struct Complex
int real_no,imaginary_no;
};
int main()
Complex c;
cout<<"Enter Real part "<<endl;
cin>>c.real_no;
cout<<"Enter Imernary part "<<endl;
cin>>c.complex_no;
cout<<"Complex no = "<<c.real_no<<"+"<<c.complex_no<<"i"<<endl;
return 0;
QUESTION NO 7
#include <iostream>
using namespace std;
const int SIZE=5;
struct Complex
int real_no,complex_no;
};
int main()
Complex c1,c2;
cout<<"Enter First Real part "<<endl;
cin>>c1.real_no;
cout<<"Enter First Imaginary part "<<endl;
cin>>c1.complex_no;
cout<<"Enter Second Real part "<<endl;
cin>>c2.real_no;
cout<<"Enter Second Imaginary part "<<endl;
cin>>c2.complex_no;
int t_real=c1.real_no+c2.real_no;
int t_imaginary=c1.complex_no+c2.complex_no;
cout<<"Complex no = "<<t_real<<"+"<<t_imaginary<<"i"<<endl;
return 0;
QUESTION NO 8
#include <iostream>
using namespace std;
const int SIZE=5;
struct Player
int distance_covered;
int Min,sec;
};
int main()
Player p,p1,p2;
cout<<"Enter distance covered in meters "<<endl;
cin>>p.distance_covered;
cout<<"Enter First player minutes "<<endl;
cin>>p1.Min;
cout<<"Enter First player seconds "<<endl;
cin>>p1.sec;
cout<<"Enter Second player minutes "<<endl;
cin>>p2.Min;
cout<<"Enter Second player seconds "<<endl;
cin>>p2.sec;
float t_time1=p1.Min+(p1.sec/60.0f);
float t_time2=p2.Min+(p2.sec/60.0f);
if(t_time1<t_time2)
cout<<"Record is "<<endl;
cout<<"First player wins "<<endl;
cout<<"Distance covered is : "<<p.distance_covered<<endl;
cout<<"Total time is : "<<t_time1<<" minutes"<<endl;
else
cout<<"Record is "<<endl;
cout<<"Second player wins "<<endl;
cout<<"Distance covered is : "<<p.distance_covered<<endl;
cout<<"Total time is : "<<t_time2<<" minutes"<<endl;
return 0;