Part I (1.5 points) Write a C++ program to find the smallest for a sequence of i
ID: 647090 • Letter: P
Question
Part I (1.5 points)
Write a C++ program to find the smallest for a sequence of integers read from the keyboard. Note that the number of integers read from the keyboard is unknown. The following shows a sample run of the program.
Enter a sequence of distinct integers: 18 -3 93 17 42
The smallest integer entered is -3
Be sure to use proper formatting and appropriate comments in your code.
Part II (1.5 points)
Write a C++ program that prints a filled right triangle of stars. Your program should first prompt the user to enter a positive integer (? 1) indicating the number of lines printed for the right triangle. The right triangle is printed as follows: one star on the first line, two on the next, and so on, up to the total number of lines. The following shows a sample run of the program.
Enter a positive integer: 10
Here comes the triangle
*
**
***
****
*****
******
*******
********
*********
**********
Be sure to use proper formatting and appropriate comments in your code.
Part III (1.5 points)
Write a C++ program that averages test scores. The program asks the user for the number of students (of type int) and the number of test scores (of type int) per student. It then computes the average (of type float with precision 2) for each student. The following shows a sample run of the program.
For how many students do you have scores? 2
How many test scores does each student have? 3
Enter score 1 for student 1: 84
Enter score 2 for student 1: 79
Enter score 3 for student 1: 97
The average score for student 1 is 86.67
Enter score 1 for student 2: 92
Enter score 2 for student 2: 88
Enter score 3 for student 2: 94
The average score for student 2 is 91.33
Be sure to use proper formatting and appropriate comments in your code.
Explanation / Answer
include <iostream>
using namespace std;
int main() {
int i,j,score,total,k;
for(i=1;i<10;i++)
{
for(j=1;j<i;j++)
{
cout<<"*";
}
cout<<endl;
}
cout<<"For how many students do you have scores?";
cin>>j;
cout<<"How many test scores does each student have?";
cin>>i;
for(int l=1;l<=j;l++)
{
for(k=1;k<=i;k++)
{
cout<<"Enter score" ;
cout<< k ;
cout<< " for student 1:" ;
cin>>score;
total=score+total;
}
int avg=total/j;
cout<< "The average score for student";
cout<<k;
cout<<"is"<<avg;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.