Use integer type values for grades and averages. Initialize all variables proper
ID: 3703374 • Letter: U
Question
Use integer type values for grades and averages. Initialize all variables properly. Initialize arrays using loops.
Read the first and last name for each student.
Read grades, names, and absences from the keyboard input real-time for each student with an infinite amount of grades as follows:
The input request should look like the below for each student (without quotes):
“Please enter Student 1’s First name:”
“Please enter Student 1’s Last name:” (on a newline)
“Please enter Student 1grade1: “
“Please enter Student 1 grade2: “ (on a newline)
etc.
Terminate the grade input when the entered grade is out of bounds (grades must be between 0 and 100).
“Please enter Student 1’s absences:” (on a newline)
Then, get Student two’s first name, last name, grades and absences.
Concatenate the each students First and Last Name so that one variable per student is used in the output for step 8 (below).
Concatenate the output to provide the list of grades in 7a and 7b. Note, casting may be required.
If the number of absences per student is less than or equal to 2, display the first and last name of the student and all grades entered per student and their grade average.
a. The output should be as below (example only based on inputted grades) :
1. “Jessie Ventura’s grades: 90, 90, 95, 99. Average is 93. Jessie Ventura’s final grade for CIS161 is an A” (see grading scale below)
b. If the number of absences is greater than 2, output the following (example):
1. “John Wayne was dropped from CIS161 due to 3 absences.” (Based on Student’s name and number of absences entered in step 5)
8. Use logical operators (Chapter 3.4) to accomplish the following: If the student has an A in the class and absences are less than 3 output the following (example) 2 blank lines down:
a. “Jessie Ventura has an A and less than 3 absences and should be recommended for Valedictorian of the Century.” (on a newline)
Extra credit: Determine if any names (first or last) entered in steps 4.a.i and 4.a.ii are blank. If they are blank, prompt the user to input that name again.
Grading scale:
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F
Explanation / Answer
PROGRAM:
#include<stdio.h>
#include<math.h>
struct student{
char firstName[100];
char SecondName[100];
float grade1,grade2,grade3,grade4;
};
void main(){
struct student std[100];
int n,i,avg;
printf("Enter No Of Student: ");
scanf("%d",&n);
for(i=0;i<n;i++){
printf("Please Enter Student %d's First Name: ",i+1);
scanf("%s",std[i].firstName);
printf("Please Enter Student %d's Second Name: ",i+1);
scanf("%s",std[i].SecondName);
printf("Please enter Student %d's first grade: ",i+1);
scanf("%f",&std[i].grade1);
printf("Please enter Student %d's Second grade: ",i+1);
scanf("%f",&std[i].grade2);
printf("Please enter Student %d's Third grade: ",i+1);
scanf("%f",&std[i].grade3);
printf("Please enter Student %d's four grade: ",i+1);
scanf("%f",&std[i].grade4);
}
for(i=0;i<n;i++){
printf("%s %s's grades: %.0f,%.0f,%.0f, and %.0f ",std[i].firstName,std[i].SecondName,std[i].grade1,std[i].grade2,std[i].grade3,std[i].grade4);
avg=(floor(std[i].grade1+std[i].grade2+std[i].grade3+std[i].grade4)/4);
printf("Their average is %d ",avg);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.