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...
(1) Define the term identifier as a name for something, such as a variable, constant, or...
(1) Define the term identifier as a name for something, such as a variable, constant, or function. (2) Define the term data type as a set of values together with a set of operations. (3) Discuss the five arithmetic operators in C++ that are used to manipulate integral and floating-type data types.
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...
A) Declare a String variable called myString0 and initialize it to "Java". B) Declare a String...
A) Declare a String variable called myString0 and initialize it to "Java". B) Declare a String variable called myString1 and initialize it to "Programming". C) Declare a String variable called myString2 and initialize it to "Language". D) Print the concatenation of myString0 + " is a " + myString1 + " " + myString2 + ".". E) Print the sum of the lengths of myString1 and myString2 (must call the length() method). F) Print the 2nd, 4th, and 7th character...
Declare and initialize an array to store the course name or code.
Declare and initialize an array to store the course name or code.
JAVASCRIPT: /* Assignment 03: Complete this javascript */ // 1) Declare a variable named myValue //...
JAVASCRIPT: /* Assignment 03: Complete this javascript */ // 1) Declare a variable named myValue // Assign myValue the value of "Hello, how's it going?" // Print the value of myValue to the console // 2) Use the charAt() method to display the letter t // from the variable myValue in the console // 3) Use the indexOf() method to display the position of "going" // from the variable myValue in the console // 4) Use the slice() method to...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT