0% found this document useful (0 votes)
379 views

Write Pseudo Code and Draw Flowchart For Each of The Problems

The document provides 13 problems to solve using C++ code. It instructs the reader to write pseudo code, draw flowcharts, write C++ code to solve each problem without errors, and test the code. The problems include determining if a number is odd or even, comparing two numbers, ordering three numbers, calculating sums, averages, and more. It then provides the full C++ source code implementing functions to solve each problem.

Uploaded by

workineh amare
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
379 views

Write Pseudo Code and Draw Flowchart For Each of The Problems

The document provides 13 problems to solve using C++ code. It instructs the reader to write pseudo code, draw flowcharts, write C++ code to solve each problem without errors, and test the code. The problems include determining if a number is odd or even, comparing two numbers, ordering three numbers, calculating sums, averages, and more. It then provides the full C++ source code implementing functions to solve each problem.

Uploaded by

workineh amare
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Write pseudo code and draw flowchart for each of the problems.

Based on your algorithm


write a C++ code to perform the required task. Your program should be error free.

1. Receive a number and determine whether it is odd or even.


2. Obtain two numbers from the keyboard, and determine and display which (if either) is
the larger of the two numbers.
3. Receive 3 numbers and display them in ascending order from smallest to largest
4. Add the numbers from 1 to 100 and display the sum
5. Add the even numbers between 0 and any positive integer number given by the user.
6. Find the average of two numbers given by the user.
7. Find the average, maximum, minimum, and sum of three numbers given by the user.
8. Find the area of a circle where the radius is provided by the user.
9. Swap the contents of two variables using a third variable.
10. Swap the content of two variables without using a third variable.
11. Read an integer value from the keyboard and display a message indicating if this
number is odd or even.
12. Read 10 integers from the keyboard in the range 0 - 100, and count how many of them
are larger than 50, and display this result
13. Take an integer from the user and display the factorial of that number

#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
using namespace std;
bool isOdd(int);
void Lager();
void Order(int, int, int);
void SumHundred();
int SumEven(int);
double Average(int, int);
void AverageMaxMinSum(int, int, int);
double CircleArea(double);
void Swap(int*, int*);
void SwapLong(int*, int*);
void OddEven();
void MoreThanFifty();
void Factorial(int);
int main()
{
int select;
cout << "============================" << endl;
//1. Receive a number and determine whether it is odd or even.; using in 11
cout << "2. Obtain two numbers from the keyboard, and determine and display " << endl <<
"which(if either) is the larger of the two numbers." << endl;
cout << "3. Receive 3 numbers and display them in ascending order from " << endl <<
"smallest to largest" << endl;
cout << "4. Add the numbers from 1 to 100 and display the sum" << endl;
cout << "5. Add the even numbers between 0 and any positive integer number " << endl <<
"given by the user." << endl;
cout << "6. Find the average of two numbers given by the user." << endl;
cout << "7. Find the average, maximum, minimum, and sum of three numbers " << endl <<
"given by the user." << endl;
cout << "8. Find the area of a circle where the radius is provided by the user." << endl;
cout << "9. Swap the contents of two variables using a third variable." << endl;
cout << "10. Swap the content of two variables without using a third variable." << endl;
cout << "11. Read an integer value from the keyboard and display a message " << endl <<
"indicating if this number is odd or even." << endl;
cout << "12. read 10 integers from the keyboard in the range 0 - 100, and " << endl <<
"count how many of them are larger than 50, and display this result" << endl;
cout << "13. Take an integer from the user and display the factorial of " << endl << "that
number" << endl;
cout << "===============================================" << endl;
cout << "Pleace Select menu number:";
cin >> select;
switch (select)
{
case 1:
{
int n;
cout << "input number:";
cin >>n;
isOdd(n);
break;
}
case 2:
{
Lager();
break;
}
case 3:
{
int n1, n2, n3;
cout << "input first number:";
cin >> n1;
cout << "input second number:";
cin >> n2;
cout << "input third number:";
cin >> n3;
Order(n1, n2, n3);
break;
}
case 4:
{
SumHundred();
break;
}
case 5:
{
int n,sum_even;
cout << "input number:";
cin >> n;
sum_even = SumEven(n);
//cout << sum_even;
break;
}
case 6:
{
int n1, n2;
double average;
cout << "input first number:";
cin >> n1;
cout << "input second number:";
cin >> n2;
average = Average(n1, n2);
//cout << "average is " << average;
break;
}
case 7:
{
int n1, n2, n3;
cout << "input first number:";
cin >> n1;
cout << "input second number:";
cin >> n2;
cout << "input third number:";
cin >> n3;
AverageMaxMinSum(n1, n2, n3);
break;
}
case 8:
{
double r, circle_area;
cout << "input radius:";
cin >> r;
circle_area = CircleArea(r);
// cout << circle_area;
break;
}
case 9:
{
int n1, n2;
cout << "input first number:";
cin >> n1;
cout << "input second number:";
cin >> n2;
Swap(&n1, &n2);
cout << endl << "first number:" << n1 << " second number:" << n2;
break;
}
case 10:
{
int n1, n2;
cout << "input first number:";
cin >> n1;
cout << "input second number:";
cin >> n2;
SwapLong(&n1, &n2);
cout << endl << "first number:" << n1 << " second number:" << n2;
break;
}
case 11:
{
OddEven();
break;
}
case 12:
{
MoreThanFifty();
break;
}
case 13:
{
int n;
cout << "input number:";
cin >> n;
Factorial(n);
break;
}
default:
break;
}
return EXIT_SUCCESS;
}
bool isOdd(int n)
{
if (n % 2 == 0) {
return false;
} else {
return true;
}
}
void Lager()
{
int n1, n2;
cout << "input first number:";
cin >> n1;
cout << "input second number:";
cin >> n2;
if (n1 > n2) cout << "first";
else if (n2 > n1) cout << "second";
else cout << "either";
cout << " is lager";
}
void Order(int n1, int n2, int n3)
{
if (n1 <= n2 && n1 <= n3) {
cout << n1 << " ";
if (n2 <= n3) cout << n2 << " " << n3;
else cout << n3 << " " << n2;
} else if (n2 <= n1 && n2 <= n3) {
cout << n2 << " ";
if (n1 <= n3) cout << n1 << " " << n3;
else cout << n3 << " " << n1;
} else {
cout << n3 << " ";
if (n1 <= n2) cout << n1 << " " << n2;
else cout << n2 << " " << n1;
}
}
void SumHundred()
{
int summ=0;
for (int i = 1; i < 101; i++)
{
summ += i;
}
cout <<"sum numbers from 1 to 100: "<< summ;
}
int SumEven(int n)
{
int summ = 0;
for (int i = 0; i < n+1; i++)
{
if (i % 2 != 0) summ += i;
}
return summ;
}
double Average(int n1, int n2)
{
return (double)(n1 + n2) / 2;
}
void AverageMaxMinSum(int n1, int n2, int n3)
{
int maximum, minimum, sum;
double average;
sum = n1 + n2 + n3;
average = (double)sum / 3;
if (n1 > n2) {
if (n1 > n3) {
maximum = n1;
if (n3 < n2) minimum = n3;
else minimum = n2;
}
else {
maximum = n3;
minimum = n2;
}
}
else if (n3 > n2) {
maximum = n3;
minimum = n1;
}
else {
maximum = n2;
if (n3 < n1) minimum = n3;
else minimum = n1;
}
cout << "average=" << average << " maximum=" << maximum << " minimum=" <<
minimum << " sum=" << sum;
}
double CircleArea(double r)
{
return M_PI*r*r;
}
void Swap(int* n1, int* n2)
{
int buff =*n1;
*n1 = *n2;
*n2 = buff;
}
void SwapLong(int* n1, int* n2)
{
if (*n1 > *n2) //overflow check
{
*n1 = *n1 - *n2;
*n2 = *n1 + *n2;
*n1 = *n2 - *n1;
}
else
{
*n2 = *n2 - *n1;
*n1 = *n1 + *n2;
*n2 = *n1 - *n2;
}
}
void OddEven()
{
int n;
cout << "input number: ";
cin >>n;
if (isOdd(n)) cout << n << " is odd";
else cout << n << " is even";
}
void MoreThanFifty()
{
int n,count=0;
for (int i = 0; i < 10; i++)
{
cout << "input integer number in the range 0 - 100:";
cin >> n;
if (n > 50) count++;
}
cout << count << " numbers is larger than 50";
}
void Factorial(int n)
{
double factorial=1;
if (n != 0)
{
for (int i = 1; i <= n; i++)
{
factorial *= i;
}
}
cout << "factorial of " << n << " is ";
cout << factorial;
}

You might also like