Sheet 2 (Variables)
Sheet 2 (Variables)
Problem 1:
Write a C++ program that read an user’s full name of console input into a
variable, then print “Hi , full name “.
Problem 2:
Write a C++ program that accepts two numbers entered by the user and
computes their Sum, Difference, Product, Quotient and Remainder.
Problem 3: (Lab)
The arithmetic mean of two numbers is the result of dividing their some by
2. The geometric mean of two numbers is the square root of their product.
The harmonic mean of two numbers is the arithmetic mean of their
reciprocals. Write a C++ Program to that takes two floating-point numbers
as inputs and displays these three means.
Problem 4:
Write a C++ program that asks the user to input the following:
• The number of gallons of gas in the tank
• The fuel efficiency in miles per gallon
• The price of gas per gallon
Then print the cost per 100 miles and how far the car can go with the gas in
the tank.
Note that:
cost per miles = miles / fuel efficiency * gas price
max distance = fuel efficiency * gas tank
Problem 6: (student)
To enter the length (in meters), width (in meters) of a rectangular carpet
and carpet price per square meter. The program should compute and
display its area, perimeter and cost of the carpet. using the following
formula: area = width * height perimeter = 2 * (width + height)
Problem 7: (student)
Write a C++ program that converts the length in feet to centimetres, you
can calculate the length in cm (LCM) by multiplying length in feet (Lft) with
30.
#include <iostream>
using namespace std;
int main() {
int num1 = 70;
double num2 = 256.783;
char ch = 'A';
return 0;
}