C++ Programs for Various Calculations and Input/Output Operations, Exams of Object Oriented Programming

C++ programs for various calculations and input/output operations. The programs include reading data from a file, writing data to a file, calculating the area of a rectangle and circle, and determining body fat percentage based on weight, wrist measurements, and hip measurement. The programs also include tax calculations and table printing.

Typology: Exams

2020/2021

Uploaded on 06/21/2021

muhammad-faizan-mughal
muhammad-faizan-mughal 🇵🇰

5 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Task 1
#include<iostream>//header file for input /output
#include<fstream>
#include<string>
using namespace std;
int main()//main function
{
//double area, str;
ifstream infile;
ofstream outfile;
infile.open("indata.txt");
outfile.open("outdata.txt");
{
string firstname,lastname;
double
area,length,width,radius,circumfernce,age,balance,interestrate;
infile >> length;
cout << "length=" << length << endl;
infile >> width;
cout << "width=" << width << endl;
area = length*width;
cout << "area =" << area << endl;
infile >> radius;
circumfernce = 3.14*radius*radius;
infile >> firstname;
infile >> lastname;
infile >> age;
infile >> balance;
infile >> interestrate;
infile.close();
outfile << "rectangle" << endl;
outfile << "length=" << length ;
outfile << "width=" << width ;
outfile << "area=" << area << endl ;
outfile << "circle" << endl;
outfile << "radius=" << radius ;
outfile << "circumfernce=" << circumfernce << endl;
outfile << "name=" << firstname ;
outfile << lastname << endl;
outfile << "age=" << age << endl;
outfile << "balance=" << balance << endl;
outfile << "interest rate=" << interestrate << endl;
}
system("pause");// for pause the output
return 0;
}
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download C++ Programs for Various Calculations and Input/Output Operations and more Exams Object Oriented Programming in PDF only on Docsity!

Task 1

#include//header file for input /output #include #include using namespace std; int main()//main function { //double area, str; ifstream infile; ofstream outfile; infile.open("indata.txt"); outfile.open("outdata.txt"); { string firstname,lastname; double area,length,width,radius,circumfernce,age,balance,interestrate; infile >> length; cout << "length=" << length << endl; infile >> width; cout << "width=" << width << endl; area = lengthwidth; cout << "area =" << area << endl; infile >> radius; circumfernce = 3.14radius*radius; infile >> firstname; infile >> lastname; infile >> age; infile >> balance; infile >> interestrate; infile.close(); outfile << "rectangle" << endl; outfile << "length=" << length ; outfile << "width=" << width ; outfile << "area=" << area << endl ; outfile << "circle" << endl; outfile << "radius=" << radius ; outfile << "circumfernce=" << circumfernce << endl; outfile << "name=" << firstname ; outfile << lastname << endl; outfile << "age=" << age << endl; outfile << "balance=" << balance << endl; outfile << "interest rate=" << interestrate << endl; } system("pause");// for pause the output return 0; }

Output

OUTPUT

TASK 3

#include//header file for input /output using namespace std; int main()//main function { char ch; int A1, A2, A3, A4, A5; int wight, wrist, wrist2, hip, forearn; float b, bodyfat, fatpercentage; cout << "enter the gender" << endl; cin >> ch;//get thr gender from user if (ch == 'm') { cout << "enter body weight "; cin >> wight;//get weight A1 = (wight0.732)8.987; cout << "enter wrist measurment at fullest point" << endl; cin >> wrist;//get from user A2 = wrist / 3.140; cout << "enter wrist at navel" << endl; cin >> wrist2;//get from user A3 = wrist20.157; cout << "enter hip measurement " << endl; cin >> hip;// get from user cout << "enter forearn measurment " << endl; cin >> forearn;//get from user A4 = hip0.249; A5 = forearn*0.434; b = A1 + A2 - A3 - A4 + A5;// apply formula cout << "B=" << b << endl; bodyfat = wight - b; cout << "bodyfat=" << bodyfat << endl;// for output

fatpercentage = bodyfat * 100 / wight; cout << "bodyfatpercentage=" << fatpercentage << endl; } if (ch == 'w')// use if statement to check the condition { cout << "enter body weight " <<endl; cin >> wight; cout << "enter wrist " << endl; A1 = (wight * 1.082) + 94.42; A3 = wrist20.157; cout << "enter hip measurement " << endl; cin >> hip;// get from user cout << "enter forearn measurment " << endl; cin >> forearn;//get from user A4 = hip0.249; A5 = forearn*0.434; b = A1 + A2 - A3 - A4 + A5;// apply formula cout << "B=" << b << endl; bodyfat = wight - b; cout << "bodyfat=" << bodyfat << endl;// for output fatpercentage = bodyfat * 100 / wight; cout << "bodyfatpercentage=" << fatpercentage << endl; } if (ch == 'w')// use if statement to check the condition { cout << "enter body weight " <<endl; cin >> wight; cout << "enter wrist " << endl; A1 = (wight * 1.082) + 94.42; A2 = wrist / 4.15; b = A1 - A2; bodyfat = wight - b; cout << "body fat=" << bodyfat << endl; fatpercentage = bodyfat * 100 / wight; cout << "body fat percentage =" << fatpercentage << endl; } system("pause");// for pause the output return 0; }

Output

#include using namespace std; int main() { int n=9; for (int i = 1; i <= n; i++) { for (int j = i; j >= 1; j--) { if (i == 1 || j == 1) { cout << j; } else { cout << j << "=="; } } cout <<endl; } system("pause"); }

Output

Task 5

#include using namespace std; int main() { int x, reverse = 0, rem; cout << "Enter number= "; cin >> x; while (x != 0) { rem = x% 10; reverse = reverse * 10 + rem; x =x/ 10; } cout << "Reverse Number = " << reverse<<endl; system("pause"); return 0; }

Output

Task 6

Output

Task 7

#include using namespace std;

int main() { int arr[9]; int n; bool flag = true; for (int i = 0; i < 9; i++) { cin >> arr[i]; } cout << "Test Score\t\tCount\n"; for (int i = 0; i < 9; i++) { n = 1; flag = true; for (int j = i + 1; j < 9; j++) { if (arr[i] == arr[j]) { n++; } } for (int k = i - 1; k >= 0; k--) { if (arr[i] == arr[k]) { flag = false; } } if (flag == true) { cout << arr[i] << "\t\t\t" << n << "\n"; } } system("pause"); return 0; }

Output

Task 8