Question

In: Computer Science

1. Declare/define the variable/constant as indicated: a. a variable to store the grade for a student...

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

Solutions

Expert Solution

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;
        }


Related Solutions

1. ​ a)​Write a Matlab program to define student grade program and student number with if-else...
1. ​ a)​Write a Matlab program to define student grade program and student number with if-else statement logic​​​​​​​​​ b)​Write a Matlab program for sensor selection of temperature, pressure, flow sensor with if-else statement logic​​​​​​​​​ ​ 2.​Assume there are four letters from an information source with probabilities as A1 0.5 A2 0.3 A3 0.1 A4 0.1 Generate the tag and find the corresponding gaps and binary values for each stage and the sequence of the symbols which are coded are a1a3a2a4a1.​​​...
Write a program in c# that declare a variable and store user name jjohn in. Then,...
Write a program in c# that declare a variable and store user name jjohn in. Then, write a statement that will make your program display at the screen the content of that variable, followed by " I would like to know your height in centimeter. Please enter it:". Then, write a statement that will store the value entered by the user, allowing decimal numbers ie some precision, a fraction part. Finally, write statements (more than one can be needed) so...
Questions: 1) // declare integer variable sum equal to zero // declare variable integer i //...
Questions: 1) // declare integer variable sum equal to zero // declare variable integer i // declare while loop condition where i is less then 25 // inside of brackets calculate the sum of i (addition) // increment i // outside the loop print the sum of values ============================================= 2) Create a sentinel value example if I press number 0 it will display the sum of data // create a scanner // prompt the user to to enter the numbers...
Update the function playScratchOffs to do the following Declare an integer variable to store the type...
Update the function playScratchOffs to do the following Declare an integer variable to store the type of scratch off (i.e. type) Declare an integer variable to store the number of scratch off (i.e. count) Declare an integer variable for loop control (i.e. c) Declare a variable of data type struct OneDollar (i.e. oneSO) Declare a variable of data type struct TwoDollar (i.e. twoSO) Declare a variable of data type struct FiveDollar (i.e. fiveSO) Write a series of printf statements to...
Declare and initialize an array to store the course name or code.
Declare and initialize an array to store the course name or code.
What does it mean to declare a variable? Give an example.
C++ programming homeworkWhat does it mean to declare a variable? Give an example.What does it mean to assign a value to a variable? Give an example.What is the different between assigning and initializing? Give examples.
Which of the following statements is NOT correct? A. It is allowed to declare a variable...
Which of the following statements is NOT correct? A. It is allowed to declare a variable and initialize it in one statement. B. Once a variable is declared and initialized, you can change its value later on. C. The variable declaration tells the compiler to allocate appropriate memory space for the variable based on its data type. D. It is allowed to declare two variables with the same name but with different data type.
How does one declare a class variable in C#?
How does one declare a class variable in C#?
A Student is trying to calculate their final grade. The student estimates the their performance on...
A Student is trying to calculate their final grade. The student estimates the their performance on the following table. You must complete the table to receive any marks. (Use at least five decimals when necessary) Category Mark out of 100 Proportion of Grade Assignment 71 0.22 Quizzes 85 Midterms 32.5 0.22 Final 31 0.39 (a)  What is the expected grade? answer: (b)  What is the standard deviation of expected grade? answer: equation editor % (c)  If a student expects to earn an additional...
1- The best choice for a data type used to store the grade to be recorded...
1- The best choice for a data type used to store the grade to be recorded at the end of the term for this course would be a(n) ____________. Valid values would be A, B, C, D, or F, no A- or B+ would be permitted, instead a single value will be stored. 2-   The best choice for a data type used to store the name of the city where you currently live would be in a(n) [a]. 3-The best...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT