Beruflich Dokumente
Kultur Dokumente
Instructions:
1. Plagiarism will not be tolerated.
2. Do not copy from any online source or from a person.
3. If you could not do any problem, leave it blank.
4. Partial marks will be given for partially solved solutions.
5. Do not forget to fill your name, id and section. Please leave
the point block as it is. Failure to fill up your name, id and
section will invalid the whole assignment.
6. You also have to rename the assignment file with your id. For
instance, the file name is “ID_ _ Assignment 2 Summer 2020” and
your id is 12345. You have to rename it as “ID_12345_Assignment 2
Summer 2020”. Unable to follow this instruction may lead to
cancel your assignment.
Problem Set:
1.Take a number form the user and check whether the number is
positive, negative or neither.
36 No
65 Yes
80 No
90 Yes
INPUT OUTPUT
36 No
65 Yes
80 No
90 Yes
6.Write a program that takes the user’s age as input and then
finds out what stage of human life they are in using the table
given below.
AGE RANGE STAGE
Less than 3 years Infancy
From 3 years to less than 12 years Childhood
From 12 years to less than 20 years Adolescence
From 20 years to less than 40 years Young adulthood
From 40 years to less than 65 years Mature adulthood
65 years and above Late adulthood
Program input/output
INPUT OUTPUT
20 Young adulthood
6 Childhood
12 Adolescence
1 Infancy
65 Late adulthood
8. Write a program thar asks the user to enter the x and y coordinates
of a point in 2-dimensional space. Then find out where the point is
located. Possible locations are the four quadrants, the two axes and
the origin. See the input-output table below.
INPUT OUTPUT
2nd 1st quadrant
X = -5 3nd quadrant quadrant
Y= -3
X-axis
X=-2.5 x-axsis
origin
Y=0
X=0 Origin
3nd 4th quadrant
Y=0 quadrant
X=0 y-Axis
Y=12
X=1.32 1st quadrant
Y=2.14
3 5 4 Right triangle
13 5 12 Right triangle
4.5 2.0 4.5 Not a right triangle
10. Write a program that ask the user to select an option for a
menu. The menu will have the following options:
1. Area of a circle
2. Are of a rectangle
3. Area of triangle
4. Volume of a cylinder
5. Volume of a sphere
6. Volume of a cube
The use will select an option by entering the corresponding serial number. For
example, let’s assume the use enters 2. That means the user wants to computer the
area of a rectangle. So, then the program asks the user to enter the length and
width of the rectangle. Once the user provides the requested inputs, the program
computes and prints the result.
INPUT OUTPUT
1. Area of circle
2. Area of a rectangle
3. Area of a triangle
4. Volume of a cylinder
5. Volume of a sphere
2. Area of a rectangle
3. Area of a triangle
4. Volume of a cylinder
5. Volume of a sphere
6. Volume of a cube
Enter width: 10
Solution of problems:
Problem 1
#include <iostream>
int main () {
int x;
cin >> x;
if (x==0)
else if (x>0)
else
return 0;
Problem 2
#include <iostream>
int main () {
float x;
cin >> x;
if (x-int(x)==0)
else
return 0;}
Problem 3
#include <iostream>
int main () {
int x;
cin >> x;
else
return 0;
}
Problem 4
#include <iostream>
int main () {
int x;
cin >> x;
{if (x % 5 == 0)
else
{if (x % 7 == 0)
else
else
return 0;
}
Problem 5
#include <iostream>
int main () {
int x;
cin >> x;
else if
cout << "A\n";
return 0;
Problem 6
#include <iostream>
int main () {
int x;
cin >> x;
else
return 0;
}
Problem 7
#include <iostream>
int main () {
char x;
cin >> x;
else
return 0;
}
Problem 8
#include <iostream>
int main () {
float x, y;
cin >> x;
cin >> y;
if (x == 0 && y == 0)
else
return 0;
}
Problem 9
#include <iostream>
#include <cmath>
int main () {
double A, B, C;
{double C1 = A;
double A1 = C;
double B1 = B;
else
{double C1 = B;
double A1 = A;
double B1 = C;
else
{double C1 = C;
double A1 = A;
double B1 = B;
else
return 0;
}
Problem 10
using namespace std;
int main() {
int select;
cin>>select;
switch(select){
case 1: {
double r;
cin >> r;
break;
case 2: {
double r, a;
cin >> r;
cin >> a;
break;
case 3: {
double r, a;
cin >> r;
cin >> a;
break;
case 4: {
double r, a;
cin >> r;
cin >> a;
cout << "Volume of Cylinder: " << 3.142*pow(r, 2)*a << endl;
break;
case 5: {
double r;
cin >> r;
cout << "Volume of Sphere: " << 3.142*pow(r, 3)*4/3 << endl;
break;
case 6: {
double r;
cin >> r;
cout << "Volume of Cube: " << pow(r, 3) << endl;
break;
return 0;