You are on page 1of 8

Q1

#include <iostream>

#include<string>

#include<math.h>

using namespace std;

struct time

int h, m, s;

void setTime()

cout << "enter hours:mins:secs - ";

cin >> h >> m >> s;

void showTime()

while (s >= 60)

s -= 60;

m++;

while (m >= 60)

m - +60;

h++;

while (h >= 24)

h -= 24;

}
cout << h << ":" << m <<":" << s << ":" << endl;

void newTime()

int sec, nhour, nmin, nsec;

cin >> sec;

nhour = sec / 3600;

nmin = (sec % 3600) / 60;

nsec = (sec % 3600) - 60 * nmin;

h = h + nhour;

m = m + nmin;

s = s + nsec;

};

int main()

time t1;

t1.setTime();

t1.showTime();

t1.newTime();

t1.showTime();

system("pause");

return 0;

}
Q2

#include <iostream>

#include<string>

#include<math.h>

using namespace std;

struct student

string name;

int age, id;

double degree[5], average = 0;

void getInfo()

cout << "enter your name : ";

getline(cin, name);

cout << "enter your age : ";

cin >> age;

cout << "enter your id : ";

cin >> id;

cout << "enter your 5 degrees";

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

cin >> degree[i];

average += degree[i];

void display()

cout << "Name : " << name << endl;

cout << "Age : " << age << endl;


cout << "id : " << id << endl;

cout << "each subject's degree" << endl;

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

cout << i + 1 << "-" << degree[i] << endl;

cout << "Average : " << (average/5) << endl;

};

int main()

student s1;

s1.getInfo();

s1.display();

system("pause");

return 0;

}
Q3

#include<iostream>

using namespace std;

struct library

int id, pages;

float price;

};

void read(library book[], int n)

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

cout << "Enter data of book number " << i + 1 << endl;

cout << "ID : ";

cin >> book[i].id;

cout << "No. of pages : ";

cin >> book[i].pages;

cout << "Price : ";

cin >> book[i].price;

void display(library book[], int n)

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

cout << "Data of book number " << i + 1 << endl;

cout << "ID : " << book[i].id << endl;

cout << "No. of pages : " << book[i].pages << endl;;

cout << "Price : " << book[i].price << endl;


}

void mostcost(library book[], int n)

int max = 0;

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

if (book[max].price > max)

max = i;

cout << "The data of most costly book is" << endl;

cout << "__________________________________" << endl;

cout << "ID : " << book[max].id << endl;

cout << "No. of pages : " << book[max].pages << endl;;

cout << "Price : " << book[max].price << endl;

int main()

library b[1000];

int n;

cin >> n;

read(b, n);

display(b, n);

mostcost(b, n);

system("pause");

return 0;

}
Q4

#include<iostream>

using namespace std;

struct dimension

float width, length;

};

struct result

float area, perimeter;

};

struct rectangle

dimension d;

result s;

};

int main()

rectangle r[5];

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

cout << "Enter length -> ";

cin>> r[i].d.length;

cout << "Enter width -> ";

cin >> r[i].d.width;

r[i].s.area = r[i].d.width * r[i].d.length;

r[i].s.perimeter = 2*(r[i].d.width + r[i].d.length);

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


{

cout << "Area No." << i + 1 << "=" << r[i].s.area << endl;

cout << "perimeter No." << i + 1 << "=" << r[i].s.perimeter << endl;

system("pause");

return 0;

You might also like