IMAGE CREDIT: GOOGLE |
question 1
1. Imagine you have been employed as a
programmer in an organization and the
company uses manual way of performing simple arithmetic calculation; develop a
simple calculator that will enable the sales personnel to perform Addition,
Multiplication, and Subbtaction. Implement this in C++ using Switch....case.
2. Develope a simple application using if statement to calculate the area of the
following shapes; Square,Rectangle and Triangle. The user should be able to
perform any of the calculation and also press a key terminate the program.
3. Write a program to determine a number press on the keyboard is even or odd number.
SOLUTION
#include <iostream>
using namespace std;
int main()
{
//Question 2
double Sarea, Tarea, rerea, side, length, base, height, width.
int option.
cout << "1. Calculate the Area of Square" << endl;
cout << "2. Calculate the Area of Triangle" << endl;
cout << "3. Calculate the Area of Rectangle" << endl;
cout << "4.Exit" << endl;
cout << "Select from an option from above: ";
cin >> option;
if(option == 1)
{
cout << "" << endl; //Creating an empty line
cout << "Area of A Square" << endl;
cout << "Enter the side of the Square :";
cin >> side;
sarea = side * side;
cout << "The area of the square of side " << side << " is: " << sarea << endl;
}
else if(option == 2)
{
cout << "" << endl; //Creating an empty line
cout << "Area of A Triangle" << endl;
cout << "Enter the height of the triangle :";
cin >> height;
cout << "Enter the base of the triangle :";
cin >> base;
tarea = (height * base)/2;
cout << "The area of the triangle of height " << height << " and base " << base << " is: " << tarea << endl;
}
else if(option == 3)
{
cout << "" << endl; //Creating an empty line
cout << "Area of A Rectangle" << endl;
cout << "Enter the length of the rectangle: ";
cin >> length;
cout << "Enter the breadth of the rectangle: ";
cin >> width;
rarea = (length * width);
cout << "The area of the rectangle of length " << length << " and width " << width << " is: " << rarea << endl;
}
else
{
exit(0);
}
return 0;
}
QUESTION 2
Imagine you have been employed as a programmer in an organization and the
company uses manual way of performing simple arithmetic calculation; develop a
simple calculator that will enable the sales personnel to perform Addition,
Multiplication, and Subbtaction. Implement this in C++ using Switch....case.
2. Developed a simple application using if statement to calculate the area of the
following shapes; Square,Rectangle and Triangle. The user should be able to
perform any of the calculation and also press a key terminate the program.
3. Write a program to determine a number press on the keyboard is even or odd
number.
SOLUTION
int main()
{
//Question 3
int number;
cout << "Enter a number: ";
cin >> number;
if(number % 2 == 0)
{
cout << "Your number " << number << " is an even number " << endl;
}
else
{
cout << "Your number " << number << " is an old number " << endl;
}
return 0;
}
Post a Comment