0% found this document useful (0 votes)
31 views8 pages

Assigment

The document contains 4 programs to calculate averages and sums from user input. The first program calculates the average grade of 10 students. The second calculates the sum of bonuses for 14 employees. The third calculates the sum of positive numbers entered by the user. The fourth calculates the average grade of 5 students or terminates if -1 is entered. Each program defines variables, uses loops to collect input, calculates the sum and average, and prints the results.

Uploaded by

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

Assigment

The document contains 4 programs to calculate averages and sums from user input. The first program calculates the average grade of 10 students. The second calculates the sum of bonuses for 14 employees. The third calculates the sum of positive numbers entered by the user. The fourth calculates the average grade of 5 students or terminates if -1 is entered. Each program defines variables, uses loops to collect input, calculates the sum and average, and prints the results.

Uploaded by

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

Q(8): A program to calculate and print out the average grade of 10

students.
1:Start
2:We define the variables, which are the number of students, the grade,
the sumand avg
3:We ask the user to enter the number of students.
4:We set the initial value of the sum to zero.
5:We set the initial value of the counter i to zero
6:create of the loop with while and the condition is i<n
7:We ask the user to enter the student's grade.
8:Then add the grade to sum
9:We repeat the previous process until the condition while is broken
10: Then display sum
11:Then calculate avg from avg =sum/n
11:display avg on the screen
12:end
------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
int i=0, n;
float grade, sum=0,avg;
cout<<"please inter the num of student\n";
cin>>n;
while(i<n)
{
cout<<"please inter the grade\n";
cin>>grade;
sum=sum+grade;
i++;
}
cout<<"\n===================================\n";
cout<<"the sum of the grade\n"<<sum;
cout<<"\n===================================";
avg=sum/n;
cout<<"\n the avg of the grade\n"<<avg;
cout<<"\n===================================";
}
------------------------------------------------------------------------------------------------
9: A program to calculate and print out the bonus grade of 14
employees.
1:Start
2:We define the variables, which are the number of works , the bonus,
the sum
3:We ask the user to enter the number of works
4:We set the initial value of the sum to zero.
5:We set the initial value of the counter i to zero
6:create of the loop with while and the condition is i<n
7:We ask the user to enter the bonus.
8:Then add the bonus to sum
9:We repeat the previous process until the condition while is broken
10: Then display sum on the screen
11:emd
------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
int i=0, n;
float bonus, sum=0,avg;
cout<<"please inter the num of employees\n";
cin>>n;
while(i<n)
{
cout<<"please inter the bonus\n";
cin>>bonus;
sum=sum+bonus;
i++;
}
cout<<"\n===================================\n";
cout<<"the sum of the bonus\n"<<sum;
cout<<"\n===================================";
avg=sum/n;
cout<<"\n the avg of the bonus\n"<<avg;
cout<<"\n===================================";
}
------------------------------------------------------------------------------------------------
Q(10): A program to calculate and print out the sum of the input
numbers entered from the user if the input number is positive only.
1:Start
2:We define the variables, which num, sum
3:We ask the user to enter the number .
4:We set the initial value of the sum to zero.
6:check the num greater than 0
7:If the number is greater than zero, we add the number to sum and the
program continues to run until the program enters a negative number
8:display the sum on the screen
9:end
#include<iostream>
using namespace std;
int main()
{
int num,sum;
cout<<"please inter the number\n";
cin>>num;
sum=0;
while(num>0)
{
sum=sum+num;
cin>>num;
}
cout<<"the sum of number\n"<<sum;
}
Q(11): Write a C++ program to calculate and print out the
average grade of 5 students or the program will terminate if
the user enters -1.
1.restart
1. Define the variables:
- i variable to track the number of entered grades.
- grade variable to store the entered student's grade.
- sum variable to calculate the total sum of grades.
- avg variable to calculate the average of grades.
- Use a while loop to repeat the process until 5 grades are entered or
until the value -1 is entered.
- In each iteration, prompt the user to enter the student's grade.
- Check if the entered value is -1, in this case, exit the loop.
- Otherwise, add the grade to the total sum and increment the value of
i by one.
3. After the loop, calculate the average of the grades by dividing the total
sum by 5.
4. Print the total sum of grades and the average.
5. End the program.
------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
int i=0;
float grade,sum=0,avg;
while(i<5)
{
cout<<"please inter the grade\n";
cin>>grade;
if(grade==-1)
{
break;
}
sum=sum+grade;
i++;
}
cout<<"\n====================\n";
cout<<"the sum of grade\n"<<sum;
cout<<"\n====================";
avg=sum/5;
cout<<"\nthe avg of the grade\n"<<avg;
cout<<"\n====================\n";
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy