Task1.Assume that you want to generate a table of multiples of any given number. Write a program
that allows the user to enter the number and then generates the table, formatting it into 10
columns and 20 lines.
#include
using namespace std;
int main()
{
int num;
int n=1;
int table;
cout<<"___________________________________________"<>num;
int i=1;
while(i<=20)
{
int j=1;
while(j<=10)
{
table=num*n;
cout<
Task 2. Suppose you give a dinner party for six guests, but your table seats only four. In how
many ways
can four of the six guests arrange themselves at the table?
Any of the six guests can sit in the first chair. Any of the remaining five can sit in the
second chair.
Any of the remaining four can sit in the third chair, and any of the remaining three can sit in
the
fourth chair. (The last two will have to stand.)
So the number of possible arrangements of six guests in four chairs is 6*5*4*3, which is 360.
Write a program that calculates the number of possible arrangements for any number of guests
and any number of chairs. (Assume there will never be fewer guests than chairs.) Don’t let this
get too complicated. A simple loop should do it.
#include
using namespace std;
int main()
{
int noOf_Guest;
int noOf_chairs;
cout << "___________________________________________" << endl;
cout << "--------------Table of a number-------------" << endl;
cout << "____________________________________________" << endl;
cout << "Enter the number of guests:" << endl;
cin >> noOf_Guest;
cout << "Enter the number of chairs:" << endl;
cin >> noOf_chairs;
while (noOf_Guest < noOf_chairs)
{
cout << "Inavalid :Input" << endl;
cout << "Number of guest are always be greater than the number of the chairs:" << endl;
cout << " Again Enter the number of guests:" << endl;
cin >> noOf_Guest;
cout << " Agin Enter the number of chairs:" << endl;
cin >> noOf_chairs;
}
int upper = noOf_Guest;
int cal_upper = 1;
int lower = noOf_Guest - noOf_chairs;
int cal_lower = 1;
while (upper != 0)
{
cal_upper = cal_upper * upper;
upper--;
}
while (lower != 0)
{
cal_lower = cal_lower * lower;
lower--;
}
float combination;
combination = (float)cal_upper / cal_lower;
cout << "The number of possible arrangements " << noOf_Guest << " number of guests and " << noOf_chairs << " number of chairs = " << combination << endl;
return 0;
}
Task 3. Create a four‐function calculator for fractions. Here are the formulas for the four
arithmetic
operations applied to fractions:
Addition : a/b + c/d = (a*d+b*c)/(b*d);
Subtraction : a/b - c/d = (a*d-b*c)/(b*d);
Multiplication : a/b * c/d = (a*c)/(b*d);
Division : a/b / c/d = (a*d)(/b*c);
The user should type the first fraction, an operator, and a second fraction. The program should
then display the result and ask whether the user wants to continue.
Do you wish to continue (y/n)?
y mean executes the above program again. n mean end the program
#include
using namespace std;
int main()
{
bool flag = true;
while (flag == true)
{
int a, b, c, d;
int upper;
int lower;
float cal;
char ch;
char wish;
cout << "___________________________________________" << endl;
cout << "--------------Fraction Calculator-------------" << endl;
cout << "____________________________________________" << endl;
cout << "Enter the fraction 1:" << endl;
cin >> a;
cout << "/" << endl;
cin >> b;
cout << "Enter the operation:" << endl;
cin >> ch;
cout << "Enter the second fraction:" << endl;
cin >> c;
cout << "/" << endl;
cin >> d;
cout << endl;
switch (ch)
{
case '+':
{
upper = ((a * d) + (b * c));
lower = (b * d);
cout << "The sum of these two fractions = " << upper << "/" << lower << endl;
break;
}
case '-':
{
upper = ((a * d) - (b * c));
lower = (b * d);
cout << "The subtraction of these two fractions = " << upper << "/" << lower << endl;
break;
}
case '*':
{
upper = (a * c);
lower = (b * d);
cout << "The Multipliaction of these two fractions = " << upper << "/" << lower << endl;
break;
}
case '/':
{
upper = (a * d);
lower = (b * c);
cout << "The division of these two fractions = " << upper << "/" << lower << endl;
break;
}
}
cout << "Do you wish to continue? Enter y or yes or n for not!" << endl;
cin >> wish;
if (wish == 'y')
{
system("cls");
flag = true;
}
else if (wish == 'n')
{
flag = false;
}
}
return 0;
}
Task 4.Write a program that asksthe user to enter today’ssalesfor five stores. The program
should then
display a bar graph comparing each store’s sales. Create each bar in the bar graph by displaying
a row of asterisks. Each asterisk should represent $100 of sales. Here is an example of the
program’s output
___________________________________________
--------------Store Sale graph-------------
____________________________________________
Enter today's sale for store 1 :
1000
Enter today's sale for store 2 :
1200
Enter today's sale for store 3 :
1800
Enter today's sale for store 4 :
800
Enter today's sale for store 5 :
1900
Sales Bar Chart :
Store 1: **********
Store 2: ************
Store 3: ******************
Store 4: ********
Store 5: *******************
#include
using namespace std;
int main()
{
float store1, store2, store3, store4, store5;
cout << "___________________________________________" << endl;
cout << "--------------Store Sale graph-------------" << endl;
cout << "____________________________________________" << endl;
cout << "Enter today's sale for store 1 :" << endl;
cin >> store1;
cout << "Enter today's sale for store 2 :" << endl;
cin >> store2;
cout << "Enter today's sale for store 3 :" << endl;
cin >> store3;
cout << "Enter today's sale for store 4 :" << endl;
cin >> store4;
cout << "Enter today's sale for store 5 :" << endl;
cin >> store5;
cout << endl;
cout << "Sales Bar Chart :" << endl;
store1 = store1 / 100;
store2 = store2 / 100;
store3 = store3 / 100;
store4 = store4 / 100;
store5 = store5 / 100;
// displays
int s1 = 1;
int s2 = 1;
int s3 = 1;
int s4 = 1;
int s5 = 1;
cout << "Store 1: ";
while (s1 <= store1)
{
cout << "*";
s1++;
}
cout << endl;
cout << "Store 2: ";
while (s2 <= store2)
{
cout << "*";
s2++;
}
cout << endl;
cout << "Store 3: ";
while (s3 <= store3)
{
cout << "*";
s3++;
}
cout << endl;
cout << "Store 4: ";
while (s4 <= store4)
{
cout << "*";
s4++;
}
cout << endl;
cout << "Store 5: ";
while (s5 <= store5)
{
cout << "*";
s5++;
}
cout << endl;
return 0;
}
Task 5. Write a program with a loop that lets the user enter a series of integers. The user should
enter
−99 to signal the end of the series. AŌer all the numbers have been entered, the program should
display the largest and smallest numbers entered.
#include
using namespace std;
int main()
{
int num=0;
int temp;
int larger;
int smaller;
cout << "___________________________________________" << endl;
cout << "--------------Greater or Smaller-------------" << endl;
cout << "____________________________________________" << endl;
while(num!=-99)
{
temp=num;
cout<<"Enter a number :"<>num;
if(num>temp)
{
larger=num;
}
else if(num
A teacher has asked all his students to line up single file according to their first name.
For example, in one class Amy will be at the front of the line and Yolanda will be at the end.
Write a program that prompts the user to enter the number of students in the class, then loops
to read that many names. Once all the names have been read it reports which student would be
at the front of the line and which one would be at the end of the line. You may assume that no
two students have the same name.
Input Validation: Do not accept a number less than 1 or greater than 25 for the number of students.
#include
#include
using namespace std;
int main()
{
int num;
string name;
string temp;
string temp1;
string temp2;
cout << "______________________________________________________________________" << endl;
cout << "--------------Class line first and last student in a list-------------" << endl;
cout << "_______________________________________________________________________ " << endl;
cout << "Enter the number of students:" << endl;
cin >> num;
while (num < 1 || num > 25)
{
cout << "Invalid Input:" << endl;
cout << "Again Enter the Number of students that are in the range of 1 to 25:" << endl;
cout << "Enter the number of students:" << endl;
cin >> num;
}
cout<<"Enter the first name of the student 1 :"<>temp;
temp1=temp;
temp2=temp;
int i=2;
while (i <= num)
{
cout<<"Enter the name of the student "<>name;
if(name>temp1)
{
temp1=name;
}
else if(name
Task 7. Write a program that asksthe user to enter the amount that he or she has budgeted for a
month.
A loop should then prompt the user to enter each of his or her expenses for the month and keep
a running total. When the loop finishes, the program should display the amount that the user is
over or under budget.
#include
#include
using namespace std;
int main()
{
float budget;
float expense=0.0;
float sum = 0;
bool flag = true;
int i = 1;
cout << "____________________________________________________" << endl;
cout << "--------------Monthly Budget calculator-------------" << endl;
cout << "_____________________________________________________" << endl;
cout << "Enter the total budget of a month:" << endl;
cin >> budget;
cout << "Enter the values of a expenses and when you enter all and finish it enter -1" << endl;
while (flag == true)
{
sum = sum + expense;
cout << "Enter an amount spent for the expense " << i << " = " << endl;
cin >> expense;
if (expense == -1)
{
flag = false;
}
i++;
}
cout << endl;
cout << "Your total bydget is = $" << budget << endl;
cout << "Your total expenses = $" << sum << endl;
if (sum > budget)
{
cout << "Your are $" << sum - budget << " over the budget:" << endl;
}
else if (sum < budget)
{
cout << "Your are $" << budget - sum << " under the budget:" << endl;
}
else
{
cout << " your expenses are equal to budget:" << endl;
}
return 0;
}
Task 8. Write a program that displays a weekly payroll report. A loop in the program should ask the
user for the employee number, gross pay, state tax, federal tax, and FICA with‐holdings.
The loop will terminate when 0 is entered for the employee number.
After the data is entered, the program should display totals for gross pay, state tax, federal tax,
FICA withholdings, and net pay.
Input Validation: Do not accept negative numbers for any of the items entered. Do not accept values
for state,
federal, or FICA withholdings that are greater than the gross pay. If the sum state tax + federal
tax + FICA
withholdings for any employee is greater than gross pay, print an error message and ask the user to
reenter the data
for that employee
#include
using namespace std;
int main()
{
cout << "____________________________________________________" << endl;
cout << "--------------Weekly payroll Report-------------" << endl;
cout << "_____________________________________________________" << endl;
int empNo = 1;
bool flag = true;
bool invalid;
float gross, state, federal, fica, reenter;
float sum_gross = 0, sum_state = 0, sum_federal = 0, sum_fica = 0, sum_reenter = 0, total_net = 0, total_pay;
while (flag == true)
{
do
{
cout << "Enter the emplyee number :" << endl;
cin >> empNo;
while (empNo < 0)
{
cout << "!INVALID INPUT:AGAIN ENTERD THE EMPLOYEE NUMBER( it should not be negative):" << endl;
cin >> empNo;
}
if (empNo == 0)
{
flag = false;
break;
}
cout << "Enter the gross value number :" << endl;
cin >> gross;
while (gross < 0)
{
cout << "!INVALID INPUT:AGAIN ENTERD THE GROSS VALUE( it should not be negative):" << endl;
cin >> gross;
}
cout << "Enter the STATE TAX :" << endl;
cin >> state;
while (state < 0)
{
cout << "!INVALID INPUT:AGAIN ENTERD THE STATE TAX( it should not be negative):" << endl;
cin >> state;
}
cout << "Enter the FEDERAL TAX: :" << endl;
cin >> federal;
while (federal < 0)
{
cout << "!INVALID INPUT:AGAIN ENTERD THE FEDERAL TAX:( it should not be negative):" << endl;
cin >> federal;
}
cout << "Enter the FICA holdings :" << endl;
cin >> fica;
while (fica < 0)
{
cout << "!INVALID INPUT:AGAIN ENTERD THE FICA holdings( it should not be negative):" << endl;
cin >> fica;
}
reenter = state + federal + fica;
if (reenter > gross)
{
invalid = false;
cout << "The sum of state tax , federal tax and FICA holdingsis greater than the gross value " << endl;
cout << "So,re-enter the values for the emplyee number :" << empNo << endl;
}
else if (reenter < gross)
{
invalid = true;
}
if (invalid == true)
{
sum_gross = sum_gross + gross;
sum_state = sum_state + state;
sum_federal = sum_federal + federal;
sum_fica = sum_fica + fica;
}
} while (invalid);
}
total_pay = sum_federal + sum_fica + sum_state;
total_net = sum_gross - total_pay;
cout << "\n Pay_Roll Weekly Report:" << endl;
cout << "The total gross value = $" << sum_gross << endl;
cout << "The total state_tax value = $" << sum_state << endl;
cout << "The total federal_tax value = $" << sum_federal << endl;
cout << "The total FICA holdings value = $" << sum_fica << endl;
cout << "The total net pay = $" << total_net << endl;
return 0;
}
Task 9. A prime number is a number that is only evenly divisible by itself and 1. For example, the
number
5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime
because it can be divided evenly by 1, 2, 3, and 6.
Write a program, which takes an integer from user and print “Number is Prime” if the number is
a prime number, or “Number is not Prime” otherwise.
#include
using namespace std;
int main()
{
int num;
bool flag=true;
int i=2;
cout << "____________________________________________________" << endl;
cout << "-------------------Prime Number---------------------" << endl;
cout << "_____________________________________________________" << endl;
cout<<"Enter a number:"<>num;
while(i
Task 10. Write a C++ program that reads an integer between 0 and 65535 from the keyboard and uses it
to seed a random number generator. Then output 20 random numbers between 1 and 100 on
screen.
#include
#include
using namespace std;
int main()
{
int num;
cout << "_______________________________________________________________" << endl;
cout << "-------------------Random Number Generator---------------------" << endl;
cout << "_______________________________________________________________" << endl;
cout << "Enter the number betwwen the 0 and 65535 :" << endl;
cin >> num;
while (num < 0 || num > 65535)
{
cout << "Inavlid Input! Plaese enter the number in the range of the 0 and 65535:" << endl;
cin >> num;
}
srand(num);
int i = 1;
while (i <= 20)
{
int x;
x = (rand() % 100) + 1;
cout << "The random number " << i << " = " << x << endl;
i++;
}
return 0;
}
Whats make this website differents from others?
Amazing Feature That Increase your Productivity
If you don't find any problem,in this website and if you have a very difficult assignment
question that
is not present on internet ,then you dont bother yourself,we are here to solve every problem
of
your
life you just click on the Problem asking button and write your problem we slove the code of
your
problem and sent you on your email addres that you put in the sin up form.