Question

In: Computer Science

Question 4 A. Suppose the following letter grade class has been defined globally in a program....

Question 4

A. Suppose the following letter grade class has been defined globally in a program.

#include <iostream>

using namespace std;

class Grade {

   private:

    char grade;

   public:

     Grade(char in_grade);

       void print( );

};

Grade::Grade ( char in_grade) {

       grade = in_grade;

}

void Grade::print ( ) {

        cout << grade;       

}

  

Write a main function that reads one character from the keyboard, create a Grade object containing that character, and then have the object print itself.

Furthermore, create an output file (named “output.txt”), and save the character to this output file. Last, close this output file.

  1. What is the output of the following C++ program ?  

int main ( )

{

      int a = 3, b= 2, c= 1, d, e, f, g;

      

      d = a&b;    e = a | c;   f = a >> 1, g = a << 1;

      cout << “d= “ << d << “ e = “ << e << “ f = “ << f << “g = “ << g << endl;

}

Solutions

Expert Solution

Code:

#include <iostream>
#include <fstream>
using namespace std;
class Grade {
private:
char grade;
public:
Grade(char in_grade);
void print( );
};

Grade::Grade (char in_grade) {
grade = in_grade;
}

void Grade::print ( ) {
cout << grade;
}

int main(){
   char in_grade;
   cout<<"Enter Grade: ";
   cin>>in_grade;
Grade grade(in_grade);
cout<<"Entered Grade is: ";
grade.print();
  
ofstream myfile;
myfile.open ("output.txt");
myfile <<"Your Grade is: "<<in_grade;
cout<<endl <<"Grade stored in file...";
myfile.close();
}

Output:

2.

a=3,b=2

d=a&b

& is bitwise and operator it will perform & operation on a’s and b’s bit values:

(3)10=(0011)2

(2)10=(0010)2

                         0011

                         0010

                                      0010

(0010)2=(2)10

So d=2.

a=3,c=2

e=a|c

| is bitwise OR operator it will perform OR operation on a’s and c’s bit values:

(3)10=(0011)2

(1)10=(0001)2

                         0011

                         0001

                                      0011

(0011)2=(3)10

So e=3.

a=3

f=a>>1

>> is bitwise right shift operator it will shift 1 bit of a’s bit values:

(3)10=(0011)2

After right shift by 1                0001

(0001)2=(1)10

So f=1.

a=3

f=a<<1

>> is bitwise left shift operator it will shift 1 bit left of a’s bit values:

(3)10=(0011)2

After left shift by 1                0110

(0110)2=(6)10

So g=6.

So Output is:

d= 2 e = 3 f = 1 g = 6


Related Solutions

Suppose the following letter grade class has been defined globally in a program. #include <iostream> using...
Suppose the following letter grade class has been defined globally in a program. #include <iostream> using namespace std; class Grade { private: char grade; public: Grade(char in_grade); }; void print( ); Grade::Grade ( char in_grade) { } grade = in_grade; void Grade::print ( ) { cout << grade; } 1.Write a main function that reads one character from the keyboard, create a Grade object containing that character, and then have the object print itself. 2. Furthermore, create an output file...
Write a program that translates a letter grade into a number grade. Letter grades are A,...
Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1 and 0. There is no F+ or F-. A “+” increases the numeric value by 0.3, a “–“ decreases it by 0.3. However, an A+ has value 4.0.4 pts Enter a Letter grade: B- The numeric value is 2.7 Your code with comments A screenshot...
write a Java program Write a program to assign a letter grade according to the following...
write a Java program Write a program to assign a letter grade according to the following scheme: A: total score >= 90 B: 80 <= total score < 90 C: 70 <= total score < 80 D: 60 <= total score < 70 F: total score < 60 Output - the student's total score (float, 2 decimals) and letter grade Testing - test your program with the following input data: test1 = 95; test2 = 80; final = 90; assignments...
This program will determine the letter grade for a student. It will ask for scores (could...
This program will determine the letter grade for a student. It will ask for scores (could be labs, activities, quizzes, or projects) and then display some basic statistics derived from the scores. In Python, Write a program that continuously asks for a non-negative score until the user enters -1. IF the user enters a valid score ask for the possible score for that assignment, we will not assume all scores will have the same maximum value. We will assume that...
Write a c++ program that given a set of letter grade/credit hour combiniation, determines the grade...
Write a c++ program that given a set of letter grade/credit hour combiniation, determines the grade point average (GPA) Each A is worth 4 points. Each B is worth 3 points. Each C is worth 2 points. Each D is worth 1 point, and Each F is worth 0 points. The total quality points earned is the sum of the product of letter grade points and associated course credit hours. The GPA is the quotient of the quality points divided...
Create the pseudocode solution to a program that calculates the final score and letter grade for...
Create the pseudocode solution to a program that calculates the final score and letter grade for one student. Please use the following grading system: 9 Homework Assignments – 100 points each 10 points 11 Quizzes – 100 points each 5 points 5 Projects – 100 points each 10 points 6 Discussion posts – 100 points each 10 points 4 Exams – 100 points each 65 points A = 90 – 100% B = 80 – 89% C = 70 –...
Write a C++ program named, myGrade.cpp, that calculates a letter grade for a student of this...
Write a C++ program named, myGrade.cpp, that calculates a letter grade for a student of this course (CSC100 online) based on three user inputs. This program should begin by printing the title of the application (program) and a brief description of what it does. (Note: this is NOT the same as the program prolog: a prolog is much more detailed, has required elements, and is intended for other programmers reading the cpp file. The title and description displayed by the...
Rewrite the grade program from Question 2.2 using a user-defined function called computegrade that takes a...
Rewrite the grade program from Question 2.2 using a user-defined function called computegrade that takes a score as its parameter and returns a grade as a string. (15 points) USING PYTHON LANGUAGE >= 0.9 A >= 0.8 B >= 0.7 C >= 0.6 D < 0.6 F Run the program repeatedly as shown below to test the various different values for input. Enter score: 0.95 A Enter score: perfect Bad score Enter score: 10.0 Bad score Enter score: 0.75 C...
Question 3 This grade has been saved to Gradebook. Your answer has been saved and sent...
Question 3 This grade has been saved to Gradebook. Your answer has been saved and sent for grading. See Gradebook for score details. Rogen Corporation manufactures a single product. The standard cost per unit of product is shown below. Direct materials—1 pound plastic at $6.00 per pound $ 6.00 Direct labor—2.5 hours at $11.30 per hour 28.25 Variable manufacturing overhead 17.50 Fixed manufacturing overhead 7.50 Total standard cost per unit $59.25 The predetermined manufacturing overhead rate is $10.00 per direct...
Richard has just been given a 4-question multiple-choice quiz in his history class. Each question has...
Richard has just been given a 4-question multiple-choice quiz in his history class. Each question has five answers, of which only one is correct. Since Richard has not attended class recently, he doesn't know any of the answers. Assuming that Richard guesses on all four questions, find the indicated probabilities. (Round your answers to three decimal places.) (a) What is the probability that he will answer all questions correctly? (b) What is the probability that he will answer all questions...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT