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

Document From Mohamed Fouad

The document contains questions and code snippets related to C++ programming. Question 1 has three parts that provide code to calculate taxes, check if a number is divisible by 11, and print a multiplication table. Question 2 has three parts with code to map letters to numbers, calculate average GPA by gender, and print a nested loop. Question 3 has code to calculate correlation between arrays, sum elements of a 2D array, and defines functions to calculate average, minimum, and count above average.

Uploaded by

NRX
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Document From Mohamed Fouad

The document contains questions and code snippets related to C++ programming. Question 1 has three parts that provide code to calculate taxes, check if a number is divisible by 11, and print a multiplication table. Question 2 has three parts with code to map letters to numbers, calculate average GPA by gender, and print a nested loop. Question 3 has code to calculate correlation between arrays, sum elements of a 2D array, and defines functions to calculate average, minimum, and count above average.

Uploaded by

NRX
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

‫]‪Quiestion [1‬‬

‫‪Quiestion [1]1‬‬

‫ملخص السؤال بيقول ان فيه ضريبه للحكومه ب‪ %4‬و‬


‫للمدينه ب‪ %2‬و ‪ %10‬ضريبه رفاهيه‪.‬‬
‫الحل األول ورقى الشركه عاوزه تاخد مبلغ معين من المنتج (الى هيدخلو اليوزر فى البرنامج)والباقى ضرايب‬
‫هنفرض ان الرقم الى هيدخلو اليوزر ‪ 100000‬دا السعر الى هيوصل للشركه عن طريق المنتج يبقى الحل كدا‬
100000=Num – Num * 16%
100000=(84/100)*Num
Num = (100/84)*100000
If we switch between (100000 and Price)
Num = Price*(100/84)
#include<iostream>
using namespace std;
int main()
{
float price, num, govtax, citytax, luxurytax;
cout << "enter the price that you want to earn \n";
cin >> price;
num = price * (100.00 / 84);
govtax = num * 0.04;
citytax = num * 0.02;
luxurytax = num * 0.10;
cout << "the price which the item will be sold by = " << num << endl;
cout << "the goverment tax(4%) = " << govtax << endl;
cout << "the citytax(2%) = " << citytax << endl;
cout << "the luxurytax(10%) = " << luxurytax << endl;
//100000 ‫للتأكيد على ان الناتج األخير ب‬
cout << "the price which wonna be took is = " << num - (luxurytax + citytax + govtax) << endl;
return 0;
system("pause");
}

Quiestion [1]2
The Output is
0-24
25-49
50-49
75-99
100-124
125-149
150-174
175-200

Quiestion [1]3
#include<iostream>
using namespace std;
int main()
{
int n, t=0, counter = 1, z, fact = 1;
do {
cout << "enter positive number \n";
cin >> n;

} while (n < 0);


z = n;
for (int i = 1;; i++) {
z /= 10;
counter++;
if (z == 0) break;
}
for (int i = 0; i < counter; i++)
{
t += fact * (n % 10);
n /= 10;
fact *= -1;
}
cout << "t = " << t << endl;
if (t % 11 == 0)cout << "is divisable by 11 \n";
}
Quiestion [2]1
#include <iostream>

using namespace std;

int main()

char a;

cin >> a;

switch (a) {

case 'A':case 'B':case 'C': cout << 2; break;

case 'D':case 'E':case 'F': cout << 3; break;

case 'G':case 'H':case 'I': cout << 4; break;

case 'J':case 'K':case 'L': cout << 5; break;

case 'M':case 'N':case 'O': cout << 6; break;

case 'P':case 'Q':case 'R':case'S': cout << 7; break;

case 'T':case 'U':case 'V': cout << 8; break;

case 'W':case 'X':case 'Y':case'Z': cout << 9; break;


case '#': cout << "done!"; break;

default: cout << "invalid input";

return 0;

Quiestion [2]2

#include<iostream>
using namespace std;
int main()
{
int counterm = 0, summ = 0, a[4], counterf = 0, sumf = 0;
char b[4];
for (int i = 0; i < 4; i++) {
cout << "enter gender then enter GPA\n";
cin >> b[i] >> a[i];
if (b[i] == 'm')
{
summ += a[i];
counterm++;
}
else if (b[i] == 'f')
{
sumf += a[i];
counterf++;
}
}
cout << "number of male is = " << counterm << endl;
cout << "avg of male gpa is = " << summ / counterm << endl;
cout << "number of female is = " << counterf << endl;
cout << "avg of female gpa is = " << sumf / counterf << endl;
}
Quiestion [2]3
#include<iostream>
using namespace std;
int main()
{
int i = 1;
while (i<=5)
{
int j = 1;
while (j <= 5)
{
cout << " " << i * j;
j++;
}
cout << endl;
i++;
}
}

Quiestion [3]
Quiestion [3]A

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int x[1000], y[1000], sumx = 0, sumy = 0, n, i, avgx, avgy, sumxpow = 0, sumypow = 0 ;
float z;
do {
cout << "enter value of n betweek 20,1000 \n";
cin >> n;
} while (n < 20 || n>1000);
cout << "enter value of Array x Then Array y \n";
for (i = 0; i < n; i++)
{
cin >> x[i] >> y[i];
sumx += x[i];
sumy += y[i];
}
avgx = sumx / n;
avgy = sumy / n;

sumx = 0;
sumy = 0;
for (i = 0; i < n; i++)
{
sumx += x[i] - avgx;
sumy += y[i] - avgy;

sumxpow += pow(x[i] - avgx, 2);


sumypow += pow(y[i] - avgy, 2);
}
z = (1.00 * sumx * sumy) / sqrt(sumxpow * sumypow);
cout << "the output === " << z << endl;
}
Quiestion [3]B
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int a[2][3] = { 9,8,15,18,3,6 }, sum = 0;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
if (i > 0 && a[i][j] % 2 == 0)
sum += 2 * a[i][j] - a[i - 1][j];
else
sum += 2 * a[i][j];
cout << "sum =" << sum << endl;
}
}
}

Output
sum =18

sum =34

sum =64

sum =91

sum =97

sum =94
Quiestion [4]

Quiestion [4]1

#include<iostream>
#include<math.h>
using namespace std;

int f(int x, int y) {


if (x >= y) return pow(x, 2) + pow(y, 2);
else return x * y;
}
int h(int x) {
if (x >= 0) return pow(x, 2);
else return -1 * pow(x, 2);
}
int main()
{
int a, b, c;
float E;
cout << "enter values of a then b then c \n";
cin >> a >> b >> c;
E = (f(3 + a, b + 2 * a) * cos(a + b)) / (f(2 * a, a + b) * h(3 * a * b));
}

Cout<<”E=”<<E<<endl;

Quiestion [4]2
#include<iostream>
#include<math.h>
using namespace std;

float getaverage(int a[], int n) {


float avg, sum = 0.0;
for (int i = 0; i < n; i++) {
sum += a[i];
}
avg = (sum) / n;
return avg;
}
int getmin(int a[], int n) {
int min = a[0];
for (int i = 1; i < n; i++) {
if (min > a[i])
min = a[i];
}
return min;

}
int getcount(int a[], int n , int avg) {
float count = 0.0;
for (int i = 0; i < n; i++) {
if (a[i] > avg) break;
count++;
}
return count;
}
int main()
{
int a[10] = { 1,2,3,4,5,6,7,8,9,10 };
cout << "average =" << getaverage(a, 10) << endl;
cout << "min =" << getmin(a, 10) << endl;
cout << "count =" << getcount(a, 10 , getaverage(a, 10)) << endl;

You might also like