0% found this document useful (0 votes)
6 views

C++ Structure

The document contains 12 C++ programs that demonstrate the use of structures, enums, and other programming concepts. The programs include calculating room volume, storing employee data, adding fractions, and determining an employee type based on input. Overall, the programs show how to define and use custom data types to organize and work with different types of data.

Uploaded by

Hadiqa tul Zahra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

C++ Structure

The document contains 12 C++ programs that demonstrate the use of structures, enums, and other programming concepts. The programs include calculating room volume, storing employee data, adding fractions, and determining an employee type based on input. Overall, the programs show how to define and use custom data types to organize and work with different types of data.

Uploaded by

Hadiqa tul Zahra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Program 1:

Program 2:
Program 3:
#include<iostream>
using namespace std;
struct dist
{
int feet;
float inches;
};
struct volume
{
dist length, width, height;
};
main()
{
volume rovol;
rovol.length.feet=14;
rovol.length.inches=8.76;
rovol.width.feet=13;
rovol.width.inches=7.78;
rovol.height.feet=12;
rovol.height.inches=9.75;
float lengthinft, widthinft, heightinft, volumeinft;
lengthinft=rovol.length.feet+(rovol.length.inches/12);
widthinft=rovol.width.feet+(rovol.width.inches/12);
heightinft=rovol.height.feet+(rovol.height.inches/12);
volumeinft=lengthinft+heightinft+widthinft;
cout<<"Volume of room: "<<volumeinft;
}
Program 4:
#include<iostream>
using namespace std;
struct employee
{
int empnum;
float empcom;
};
main()
{
employee e1,e2,e3;
cout<<"Enter employee number for 1st employee: ";
cin>>e1.empnum;
cout<<"Enter employee's compensation for 1st employee: ";
cin>>e1.empcom;
cout<<"Enter employee number for 2nd employee: ";
cin>>e2.empnum;
cout<<"Enter employee's compensation for 2nd employee: ";
cin>>e2.empcom;
cout<<"Enter employee number for 3rd employee: ";
cin>>e3.empnum;
cout<<"Enter employee's compensation for 3rd employee: ";
cin>>e3.empcom;
cout<<"Employee number of employee 1 is "<<e1.empnum<<" and his
compensation is: "<<e1.empcom;
cout<<"\nEmployee number of employee 2 is "<<e2.empnum<<" and his
compensation is: "<<e2.empcom;
cout<<"\nEmployee number of employee 3 is "<<e3.empnum<<" and his
compensation is: "<<e3.empcom;
}
Program 5:

Program 9:
Program 8:

Program 10:
Program 11:
#include<iostream>
using namespace
std;
struct time
{
int hours,min,sec;
};
main()
{
time t1,t2,t3;
long totsec;
char s;
cout<<"Enter 1st time in format hh:min:sec: ";
cin>>t1.hours>>s>>t1.min>>s>>t1.sec;
cout<<"Enter 2nd time in format hh:min:sec: ";
cin>>t2.hours>>s>>t2.min>>s>>t2.sec;
totsec=(t1.hours+t2.hours)*3600+(t1.min+t2.min)*60+t1.sec+t2.sec;
cout<<"Total seconds are: "<<totsec<<endl;
t3.hours=totsec/3600;
totsec=totsec%3600;
t3.min=totsec/60;
t3.sec=totsec%60;
cout<<"Converted time is: "<<t3.hours<<s<<t3.min<<s<<t3.sec;
}
Program 12:
#include<iostream>
using namespace std;
struct fraction
{
int num, den;
};
main()
{
char s, op;
fraction f1,f2,sum,sub,mul,div;
cout<<"Enter 1st fraction: ";
cin>>f1.num>>s>>f1.den;
cout<<"Enter 2nd fraction: ";
cin>>f2.num>>s>>f2.den;
cout<<"Enter operator: ";
cin>>op;
switch(op)
{
case '+':
sum.num=(f1.num*f2.den)+(f1.den*f2.num);
sum.den=f1.den*f2.den;
cout<<"Sum is "<<sum.num<<s<<sum.den;
break;
case '-':
sub.num=(f1.num*f2.den)-(f1.den*f2.num);
sub.den=f1.den*f2.den;
cout<<"Subtraction is "<<sub.num<<s<<sub.den;
break;
case '*':
mul.num=(f1.num*f2.num);
mul.den=f1.den*f2.den;
cout<<"Multiplication is "<<mul.num<<s<<mul.den;
break;
case '/':
div.num=f1.num*f2.den;
div.den=f1.den*f2.num;
cout<<"Division is "<<div.num<<s<<div.den;
break;
}
}
Program 6:
#include<iostream>
using namespace std;
enum etype{accountant,laborer,secretary,manager,executive,researcher};
main()
{
char option;
etype employee;
cout<<"(accountant,reasearcher,laborer,secretary,manager,executive)";
cout<<"\n Enter employee type only 1st letter: ";
cin>>option;
switch(option)
{
case'A':
case'a':
employee=accountant;
break;
case'R':
case'r':
employee=researcher;
break;
case'L':
case'l':
employee=laborer;
break;
case'S':
case's':
employee=secretary;
break;
case'M':
case'm':
employee=manager;
break;
case'E':
case'e':
employee=executive;
break;
default:
cout<<"Invalid option.";
break;
}
switch(employee)
{
case accountant:
cout<<"Employee type is accountant.";
break;
case researcher:
cout<<"Employee type is researcher.";
break;
case laborer:
cout<<"Employee type is laborer.";
break;
case secretary:
cout<<"Employee type is secratary.";
break;
case manager:
cout<<"Employee type is manager.";
break;
case executive:
cout<<"Employee type is executuive.";
break;
default:
cout<<"Invalid choice.";
break;
}
}
Program 7:

You might also like