Thursday, 26 May 2016
Q: Write a program that declares a structure Book to store BookId, book name and price. it declares another structure Order that contains Orderid and an array of Book of length 5. The program should define a variable of type Order and input the values from the user. The program finally displays the values.
Program:
#include<iostream.h>
#include<conio.h>
struct Book
{
int b_id;
char b_name[30];
int price;
};
struct Order
{
int order_id;
Book b[5];
};
void main()
{
Order c;
cout<<"Enter your Order Id: ";
cin>>order_id;
cout<<"Enter details of five books: ";
for(int i=0;i<5;i++)
{
cout<<"Enter Book Id: ";
cin>>c.b[i].b_id;
cout<<"Enter Book Name: ";
cin>>c.b[i].b_name;
cout<< " Enter Price of the Book: ";
cin>>c.b[i].price;
}
cout<<"\n Order details is as follows: "<<endl;
cout<<" Order Id: "<<order_id<<endl;
cout<<" Book Id\t Book Name \t Price "<<endl;
for(i=0;i<5;i++)
{
cout<<c.b[i].b_id<<"\t"<<c.b[i].b_name<<"\t"<<c.b[i].price<<endl;
}
getche();
}
Q: Write a program that that declares a structure to store income, tax rate and tax of a person. the program defines an array of structure to store the record of five persons. it inputs income and tax rate of five persons and then displays the tax payable.
Program
#include<iostream.h>
#include<conio.h>
struct TaxPayable
{
double income, tax_rate, taxes;
};
void main()
{
TaxPayer p[5];
int i;
cout<<"Enter annual income and tax rate of 5 persons: \n";
for(i=0;i<5;i++)
{
cout<<"Enter annual income of tax payer #" <<i+1<<" : ";
cin>>p[i].income;
cout<<"Enter tax rate of tax payer #"<<i+1<<" : ";
cin>>p[i].tax_rate;
p[i].taxes=p[i].income*p[i].tax_rate/100;
}
cout<<" Taxes due for this year: \n";
for(i=0;i<5;i++)
cout<<" Tax Payer # "<<i+1<<" : "<<" Rs. "<<p[i].taxes<<endl;
getche();
}
Q: Write a program that declares a structure to store the code number, salary and grade of an employee. the program defines two structure variables, inputs records of two employees and the displays the record of the employee with more salary.
Program:
#include<iostream.h>
#include<conio.h>
struct employee
{
int code_num;
int salary;
int grade;
};
void main()
{
employee e1, e2;
cout<<" Enter the code number, salary and grade of the first employee:";
cin>>e1.code_num<<e1.salary<<e1.grade;
cout<<"Enter the code number, salary and grade of the second employee:";
cin>>e2.code_num<<e2.salary<<e2.grade;
cout<<" The Employee with more salary is: "<<endl;
if(e1.salary>e2.salary)
{
cout<<" Code Number "<<e1.code_num<<endl;
cout<<" Salary "<<e1.salary<<endl;
cout<< " Grade "<<e1.grade;
}
else
{
cout<< " Code Number "<<e2.code_num<<endl;
cout<<" Salary "<<e2.salary<<endl;
cout<<" Grade "<<E2.grade;
}
getche();
}
Q: Write a program that declares a structure to store the distance covered by an player along with the minutes and seconds taken to cover the distance. The program should input the records of two players and then display the record of the winner.
Program:
#include<iostream.h>
#include<conio.h>
struct player
{
int dis;
int min;
int sec;
};
void main()
{
player p1,p2;
float t1, t2;
clrscr();
cout<<" Enter distance covered the first player: ";
cin>>p1.dis;
cout<<" Enter minutes and seconds covered by the player: ";
cin>>p1.min>>p1.sec;
cout<<" Enter the distance covered the second player: ";
cin>>p2.dis;
cout<<"Enter minutes and seconds covered by the player: ";
cin>>p2.min>>p2.sec;
time1=(p1.min*60+p1.sec)/p1.dis;
time2=(p2.min*60+p2.sec)/p2.dis;
if(time1<time2)
{
cout<<"Player 1 distance: "<<p1.dis<<" miles in "<<p1.min<< " minutes "<<p1.sec<<" seconds."<<endl;
}
else
{
cout<<" Player 2 distance: "<<p2.dis<<" miles in "<<p2.min<< " minutes "<<p2.sec<<" seconds."<<endl;
}
getche();
}
Subscribe to:
Posts (Atom)