Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the rational class interface below: class rational { public: rational(); r

ID: 3574090 • Letter: G

Question

Given the rational class interface below:

class rational {

public:

   rational();

   rational(int, int);

   void input();

   // prompt user to enter two values for a rational number

   // Postcondition: the data members of the calling object is loaded with the two values enters by the user

   void display();

   // Postcondition: the contents of the calling object is displayed in "a/b" format, e.g., 1/2. -2/3, etc.

   rational add(const rational &) const;

   rational subtract(const rational &) const;

   rational multiply(const rational &) const;

   rational divide(const rational &) const;

private:

   int num;

   int denom;

};

Implement all member functions.

Write a main function to test all member functions

Your program output should be similar to the following sample display. Notice that r2 is initialized by the second constructor to a value of 1/3 and r1 is declared as a no parameter object (calling the default constructor) and it gets its value of 1/4 by calling the input member function.

C:Windowstsystem321cmd.exe Enter the name of student (e. 9 Doe John) Doe, John Enter scores for two quizze (0-10), midterm (0-100), & final (O-100) 7 8 85 94 xxx Performance record of Doe John xxx Test scores: Quiz #1 7 Quiz #2: 8 Midterm 85 Final 94 Average 87.0 Letter grade B Press any key to continue

Explanation / Answer

import java.util.Scanner;

public class Score {

   public static void main(String[] args) {

       char ch = 'Y';

       String name;

       int q1,q2,m,f;

       while (ch == 'Y' || ch == 'y') {

           System.out.println("Enter name of the student");

           Scanner in = new Scanner(System.in);

           name=in.next();

           System.out.println("Enter scores for 2 quizze (0-10) ,midterm (0-100),final(0-100) :");

           q1=in.nextInt();

           q2=in.nextInt();

           m=in.nextInt();

           f=in.nextInt();

           System.out.println("*** performance Record for "+name+" ***");

           System.out.println(" Test Scores:");

           System.out.println(" Quiz #1: "+q1);

           System.out.println(" Quiz #2: "+q2);

           System.out.println(" Midterm: "+m);

           System.out.println(" Final: "+f+" ");

           int avg =(((q1+q2)*10)+m+f)/4;

           System.out.println(" Average:"+avg);

           if(avg>90)

           System.out.println(" LetterGrade: A");

           else if(avg>80)

               System.out.println(" LetterGrade: B");

           else if(avg>70)

               System.out.println(" LetterGrade: C");

           else if(avg>60)

               System.out.println(" LetterGrade: D");

           else

               System.out.println(" LetterGrade: E");

           System.out.println(" Enter Y or y to continue");

           ch=in.next().charAt(0);

       }

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote