Professional Documents
Culture Documents
Course
Course
int main()
{
//declare varible
int sum1;
int sum2;
int num;
//input data
cout << "Enter password(six-digit):";
cin >> num;
//processing data
if (num < 100000 || num>999999) {
cout << "Error: You did not enter a six-digit integer." << endl;
return 0;
}
sum1 = (num / 100000) + ((num / 10000) % 10) + ((num / 1000) % 10);
sum2 = ((num / 100) % 10) + ((num / 10) % 10) + (num % 10);
//output data
if (sum1 == sum2) {
cout << "The number " << num << " is a lucky number!" << endl;
}
else {
cout << "The number " << num << " is not a lucky number." << endl;
}
return 0;
}
Exercise 2. The user enters a four-digit number. It is necessary to change 1 and 2, 3 and 4 digits of
this number. If the user enters not a four-digit number, an error message is output.
#include <iostream>
using namespace std;
#include <iostream>
using namespace std;
int main()
{
//declare varible
int num;
//input data
cout << "enters a four-digit number:";
cin >> num;
//processing data
if (num < 1000 || num>9999) {
cout << "Error: You did not enter a four-digit integer." << endl;
return 0;
}
//output data
cout << num << " have been enter." << endl;
return 0;
}
Exercise 3. The user enters from the keyboard 7 integers. Write a program that determines a
maximum integer among these 7 integers (The hint is that the solution must be simple).
#include <iostream>
using namespace std;
int main()
{
//declare varible
int num;
//input data
cout << "enters a 7-digit number:";
cin >> num;
//processing data
if (num < 1000000 || num>9999999) {
cout << "Error: You did not enter a 7-digit integer." << endl;
return 0;
}
//output data
cout << num << " have been enter." << endl;
return 0;
}
Exercise 4. The cargo aircraft should fly with a cargo from point A to point C through point B. The
fuel tank capacity of the cargo aircraft is 300 liters. The fuel consumption per 1 km, depending on the
weight of cargo of the aircraft, is following: up to 500 kg: 1 liter / km; up to 1000 kg: 4 liters / km; up to
1500 kg: 7 liters / km; up to 2000 kg: 9 liters / km; more than 2,000 kg - the plane does not lift. The user
inputs a distance between points A and B, B and C, and the weight of cargo. The program must calculate
what minimum amount of fuel is necessary for refueling the aircraft in point B, in order to fly from point
A to point C. If you can’t overcome any of given distances - the program should display a message about
the impossibility to fly according to the entered route.
#include <iostream>
using namespace std;
int main()
{
//declare varible
int distanceAB;
int distanceBC;
int cargoWeight;
int fuelConsumption;
int totalDistance;
int fuelNeeded;
int fuelToRefuel;
//input data
cout << "enter the distance between point A and B (KM):";
cin >> distanceAB;
cout << "Enter the distance between points B and C (km): ";
cin >> distanceBC;
cout << "Enter the weight of the cargo (in kg): ";
cin >> cargoWeight;
//processing data
if (cargoWeight > 2000) {
cout << "Error: The plane cannot lift more than 2,000 kg." << endl;
return 0;
}
fuelConsumption;
if (cargoWeight <= 500) {
fuelConsumption = 1;
}
else if (cargoWeight <= 1000) {
fuelConsumption = 4;
}
else if (cargoWeight <= 1500) {
fuelConsumption = 7;
}
else {
fuelConsumption = 9;
}
Exercise 5. The user enters two dates (day, month and year as integers). It is necessary to determine
and display a number of days between these two dates. The calculations must take into account leap
years, as well as a correct number of days in months (March - 31 September - 30, February of the non-
leap year - 28, etc.)
int main() {
//declare varible
int sales;
double salary1, salary2, salary3;
double bonus = 200;
double maxSalary;
//input data & processing data
cout << "Enter the sales for manager 1: ";
cin >> sales;
if (sales <= 500) {
salary1 = 200 + (sales * 0.03);
}
else if (sales <= 1000) {
salary1 = 200 + (500 * 0.03) + ((sales - 500) * 0.05);
}
else {
salary1 = 200 + (500 * 0.03) + (500 * 0.05) + ((sales - 1000) * 0.08);
}
cout << "Manager 1's salary is $" << salary1 << endl;