0% found this document useful (0 votes)
19 views3 pages

C++ Assignment

c++ ass

Uploaded by

iviuzoyi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

C++ Assignment

c++ ass

Uploaded by

iviuzoyi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Question 1:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
double n1, n2;
char choice;
// here we ask the user to enter a certain character for the operation they want to use
cout << "For Addition enter '+'\nFor Subtraction enter '-'\nFor Multiplication enter '*'\nFor Division
enter '/'\n";
cout << "For square root enter 'S'\nFor Cubic root enter 'C' \nFor Power of a number enter 'P'\n";
cin >> choice;
if (choice == '+')
{
cout << "Please enter two numbers\n";
cin >> n1 >> n2; //the user inputs
cout << n1 << "\t+\t" << n2 << "\t=\t" << n1 + n2 << endl; //the displayed answer
}
else if (choice == '-')
{
cout << "Please enter two numbers\n";
cin >> n1 >> n2;
cout << n1 << "\t-\t" << n2 << "\t=\t" << n1 - n2 << endl;
}
else if (choice == '*')
{
cout << "Please enter two numbers\n";
cin >> n1 >> n2;
cout << n1 << "\t*\t" << n2 << "\t=\t" << n1 * n2 << endl;
}
else if (choice == '/')
{
cout << "Please enter two numbers\n";
cin >> n1 >> n2;
cout << n1 << "\t/\t" << n2 << "\t=\t" << n1 / n2 << endl;
}
else if (choice == 'S'|| choice == 's')//so the useer can enter s small or S capital
{
cout << "Please enter a number\n";
cin >> n1;
cout << n1 << "^1/2\t" << "=\t" << sqrt(n1) << endl;
}
else if (choice == 'C' || choice == 'c') //so the user can enter c small or C capital
{
cout << "Please enter a number\n";
cin >> n1;
cout << n1 << "^1/3\t" << "=\t" << cbrt(n1) << endl;
}
else if (choice == 'P'|| choice == 'p') //so the user can enter p small or P capital
{
cout << "Please enter a number and the power\n";
cin >> n1 >> n2;
cout << n1 << "^" << n2 << "\t=\t" << pow(n1, n2) << endl;
}
else
cout << " Please enter a vaild input\n";
return 0;
}
Question 2:
#include <iostream>
using namespace std;

int main()
{
int ID, C; //the ID is a number
double tot;
string name;
cout << "Please enter your ID\n";
cin >> ID;
cout << "Please enter your name\n";
cin >> name;
cout << "Please enter amount of units of electricity consumed\n";
cin >> C;
cout <<
"*********************************************************************************************************\n\
n";//to look better
if (C > 0 && C < 200)
{
tot = C * 1.2;//equation
cout << "I.D : " << ID << endl << endl << name << " you consumed " << C << " units of
electricity\n\n";// displays an appropiate message
cout << "The total amount to be paid is " << tot << " EGP" << endl; //total message
}
else if (C >= 200 && C < 400)
{
tot = C * 1.5;
cout << "I.D : " << ID << endl << endl << name << " you consumed " << C << " units of
electricity\n\n";
cout << "The total amount to be paid is " << tot << " EGP" << endl;
}
else if (C >= 400 && C < 600)
{
tot = C * 1.8;
cout << "I.D : " << ID << endl << endl << name << " you consumed " << C << " units of
electricity\n\n";
cout << "The total amount to be paid is " << tot << " EGP" << endl;
}
else if (C >= 600)
{
tot = C * 2;
cout <<"I.D : "<< ID << endl << endl << name << " you consumed " << C << " units of
electricity\n\n";
cout << "The total amount to be paid is " << tot << " EGP"<< endl;
}
else
cout << "Please enter a vaild input\n";
}
Question 3:
#include <iostream>
using namespace std;

int main()

{
double n1, n2,n3;
cout << "enter 3 numbers\n";
cin >> n1 >> n2 >> n3;
cout << "********************************************************\n\n";//for display

if (n1 < n2 && n1 < n3 && n2 < n3)


cout << n1 << "\t<\t" << n2 << "\t<\t" << n3 << endl;

else if (n1 < n2 && n1 < n3 && n3 < n2)


cout << n1 << "\t<\t" << n3 << "\t<\t" << n2 << endl;
//the two above for n1 being the smallest number

else if (n2 < n1 && n2 < n3 && n1 < n3)


cout << n2 << "\t<\t" << n1 << "\t<\t" << n3 << endl;

else if (n2 < n1 && n2 < n3 && n3 < n1)


cout << n2 << "\t<\t" << n3 << "\t<\t" << n1 << endl;
//the two above for n2 being the smallest number

else if (n3 < n1 && n3 < n2 && n1 < n2)


cout << n3 << "\t<\t" << n1 << "\t<\t" << n2 << endl;

else if (n3 < n1 && n3 < n2 && n2 < n1)


cout << n3 << "\t<\t" << n2 << "\t<\t" << n1 << endl;
//the two above for n3 being the smallest number

else
cout << "invalid input\n";
}

You might also like