In: Computer Science
1. Declare/define the variable/constant as indicated: a. a variable to store the grade for a student (as whole number) b. a variable to store a letter grade for a course, like A, B, or C c. a variable to store an average for a student (may have decimal places) d. a variable to represent if a student passed the course or not, with a value of TRUE or FALSE e. a constant to represent the passing grade of 65 2. Using the variables declared above and any other you may need, write the program segment to read 4 values into the student’s grade (using only the variable you declared in a. above), You will need to keep track of the sum as you read. find the student’s average as a real number, to be stored in variable d above. Print the average determine if the student passed and store that value in d. above, using the constant defined in e. above, and print an appropriate message
Since you haven't provided which language to use, I shall provide the code for both C++ and Java.
Java code:
import java.util.*;
import java.io.*;
class Main {
static int value = 65; // 1.(e)
public static void main (String[] args) {
double marks; // 1.(a)
char grade; // 1.(b)
double average; // 1.(c)
boolean pass; // 1.(d)
double sum = 0.0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter grades:");
int count=4;
while(count-->0){
marks = sc.nextDouble();
sum = sum+marks;
}
average = sum/4;
System.out.println("Student's average = "+ average);
if(average>=value){
pass = true;
System.out.println("Congrats! You passed!");
}else{
pass = false;
System.out.println("You failed!");
}
}
}
C++ code:
#include <iostream>
using namespace std;
int main(){
double marks; // 1.(a)
char grade; // 1.(b)
double average; // 1.(c)
bool pass; // 1.(d)
const int value = 65; // 1.(e)
double sum = 0.0;
cout<<"Enter grades:"<<endl;
int count=4;
while(count-->0){
cin>>marks;
sum = sum+marks;
}
average = sum/4;
cout<<"Studen't average = "<<average<<endl;
if(average>=value){
pass = true;
cout<<"Congrats! You passed!"<<endl;
}else{
pass = false;
cout<<"You failed!"<<endl;
}
return 0;
}