You are on page 1of 10

[Year]

LAB #09
SUBMITTED BY : IRTAZA ALI NASIR
SUBMITTED TO : SIR ASAD
REG # 200901099
Q 1 Define a struct type that contains a person’s name consisting of a first
name and a second name, plus the person’s phone number. Use this struct in a
program that will allow one or morenames and corresponding numbers to be
entered and will store the entries in an array of structures. The program
should allow a second name to be entered and output all thenumbers
corresponding to the name, and optionally output all the names with
their corresponding numbers.

ASSINGED PROGRAM:
#include <iostream>
#include<iomanip>
#include<string>
using namespace std;
struct persons
{
string first_name[50];
string second_name[50];
unsigned int num[12];
};
int main()
{
persons prsn;
int n, num;
cout << "NUMBER OF PERSONS IN DATA " << endl;
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "PERSON FIRST NAME: " << i + 1 << endl;
cin >> prsn.first_name[i];
cout << "PERSON SECOND NAME " << i + 1 << endl;
cin >> prsn.second_name[i];
cout << "ENTER PHONE NUMBER " << i + 1 << endl;
cin >> prsn.num[i];
}
cout << "\nNAMES" << setw(34) << "phone numbers" << endl;
for (int i = 0; i < n; i++)
{
cout << ":\n" << prsn.first_name[i] << " " <<
prsn.second_name[i] << setw(25) << prsn.num[i] << endl;
}
}
RESULT
ON
SECREEN
Q.2 Write a C++program that compute Net Salary of Employee. Your
program must contain two user defined functions empSalary() and
display().• Create a structure of Employee that contains following
data members:o Employee Number, Name, BasicSalary,
HouseAllowence, MedicalAllowence,Tax,GrossPay and NetSalary•
empSalary() compute salary with given criteria House Allowence =
10% of Basic Salary Medical Allowence = 5% of Basic Salaryo Tax =
4 % of Basic Salaryo GrossSalary =
Basic+HouseAllowence+MedicalAllowenceo NetSalary =
GrossSalary –Tax• display() for displaying details of Empolyee

ASSINGED
PROGRAM
#include <iostream>
#include <string>
using namespace std;
struct employee {
string name = "IRTAZA";
long num = 33394;
int basicsalary = 150000;
int houseall = 0;
int medall = 0;
int tax = 00;
int gp = 0;
int np = 0;
};
employee salary(employee emp)
{

emp.houseall = (emp.basicsalary * 10) / 100;


emp.medall = (emp.basicsalary * 5) / 100;
emp.tax = (emp.basicsalary * 4) / 100;
emp.gp = emp.medall + emp.houseall + emp.basicsalary;
emp.np = emp.gp - emp.tax;
return emp;
}
void display(employee emp)
{

cout << "EMPLOYEE PAY SLIP" << endl << endl;


cout << "NAME" << endl;
cout << emp.name << endl;
cout << "EMPLOYEE NUMBER:" << endl; cout << emp.num << endl;
cout << "NET PAY :" << endl;cout << emp.np << endl;
cout << "GROSS PAY :" << endl;cout << emp.gp << endl;
cout << "TAX :" << endl;cout << emp.tax << endl;
cout << "MEDICAL ALLOUNCW :" << endl;cout << emp.medall << endl;
cout << "HOUSE ALLOUNCE :" << endl;cout << emp.houseall << endl;
}
int main()
{
employee emp;
emp = salary(emp);
display(emp);
cout << "have a nice day" << endl;

RESULT ON
SECREEN
Q .3 Write a C++program for billing system of different computer parts. The
program shouldperform following tasks:• Show menu to customer for orders.•
Allow the customer to select more than one item from the menu.• Calculate
and print the bill.Assume that the shop offers the following items (the price of
each item is shown to the right ofthe item):• Mouse $13.45• Keyboard $45.2•
USB $1.00• Printer $120.99• Scanner $230.90• Modem $100.00• Speaker
$50.00• Hard Drive $200.45
ASSINGED
PROGRAM
#include<iostream>
#include <stdio.h>
#include<iomanip>
using namespace std;
struct Parts {
string menuItems[8];
double menuPrice[8];
};
void showMenu(Parts);
int getData(Parts);
double printCheck(Parts);
int main()
{
Parts c;
showMenu(c);
printCheck(c);
}

void showMenu(Parts)
{
Parts c = { {" Mouse","Keyboard","
USB","Printer","Scanner","Modem","Speaker","Harddrive" },{ 13,34,1,120,230,100,50,200.45}
};
int i;
cout << "\t\t MENU" << endl << endl << "\t\tITEMS PRICE IN $ " << endl <<
endl;
for (i = 0; i < 8; i++) {
cout << setw(10) << i + 1 << setw(17) << c.menuItems[i] << setw(15) << "$"
<< c.menuPrice[i] << setw(17) << endl;
}
}

int getdata(Parts)
{

Parts p = { {" Mouse","Keyboard","


USB","Printer","Scanner","Modem","Speaker","Harddrive" },{ 13,34,1,120,230,100,50,200.45}
};

}
double printCheck(Parts p) {

int i;
char y;
double k, menuList[10], price, tax;
while (y != 'n')
{
cout << endl << "Please Enter the item number you want to buy : ";
cin >> k;
if (k == 1)
menuList[i] = 13.45;
else if (k == 2)
menuList[i] = 45.2;
else if (k == 3)
menuList[i] = 1.00;
else if (k == 4)
menuList[i] = 120.99;
else if (k == 5)
menuList[i] = 230.90;
else if (k == 6)
menuList[i] = 100.00;
else if (k == 7)
menuList[i] = 50.00;
else if (k == 8)
menuList[i] = 200.45;
price += menuList[i];
cout << "\nDo you want to buy another item?" << endl << " if not enter n if
yes enter y " << endl;
cin >> y;

}
tax = (price * 5) / 100;
price += tax;
cout << "\nTotal Price with 5% of tax is : " << price << endl;

RESULT ON
SECREEN:

You might also like