Question

class Student public: string int int Name; Midterm; Final; Student(string name, int midterm, int final) : Name (name), Midter

Write a test case assuming the Catch framework that tests the ExamAvg() method. Your test case should provide the input, the output, and precise comparison.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file

#include "catch.hpp"

#include <iostream>

using namespace std;

class Student {

    public:

    string Name;

    int Midterm;

    int Final;

    

    Student(string name,int midterm,int final) :

    Name(name),Midterm(midterm),Final(final)

    {}

    double exmAvg()

    {

        return(this->Midterm + this->Final)/2.0;

    }

};

TEST_CASE( "exmAvg are computed", "[Average]" ) {

    SECTION( "Student Abhi with midterm=20 and final=60" ) { // Average of 20 and 60 is 40

Student st = Student("Abhi",20,60);

    REQUIRE( st.exmAvg() == 40 );

}

SECTION( "Student Ram with midterm=10 and final=30" ) { // Average of 10 and 30 is 20

Student st = Student("Ram",10,30);

    REQUIRE( st.exmAvg() == 20 );

}

SECTION( "Student Kartik with midterm=15 and final=45" ) {  // Average of 15 and 45 is 30

Student st = Student("Kartik",15,45);

    REQUIRE( st.exmAvg() == 30 );

}

SECTION( "Student Amit with midterm=12 and final=33" ) {    // Average of 12 and 33 is 22.5

Student st = Student("Amit",12,33);

    REQUIRE( st.exmAvg() == 22.5 );

}

}


Student(string name, int midterm, int final) : Name(name), Midterm(midterm), Final(final), {} double exmAvg() 18 return(this-

Add a comment
Know the answer?
Add Answer to:
Write a test case assuming the Catch framework that tests the ExamAvg() method. Your test case...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double...

    A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double GPA(=(4.0*NumberOfAs+3.0*NumberOfBs+2.0*NumberOfCs+1.0*NumberOfDs)/( As+Bs+Cs+Ds+Fs)); Public data member, void setFirstName(string name); string getFirstName() const; void printFirstName() const; void getLastName(string name); string getLastName() const; void printLastName() const; void computeGPA(int NumberOfAs,int NumberOfBs,int NumberOfCs,int NumberOfDs,int NumberOfFs); double getGPA() const; double printGPA() const; A destructor and an explicit default constructor initializing GPA=0.0 and checking if GPA>=0.0 by try{}catch{}. Add member function, bool operator<(const Student); The comparison in this function based on...

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • I need help to write a test case. 1. Go to the ConcertTicketTest.java file and write...

    I need help to write a test case. 1. Go to the ConcertTicketTest.java file and write test cases for the compareTo method you just implemented. /* ConcertTicket.java file */ package SearchingSorting; /** * * @author clatulip */ public class ConcertTicket implements Comparable<ConcertTicket> { private String name; private int price; private char row; private int seat; public ConcertTicket(String name, int price) { this.name = name; this.price = price; // randomly create a row and seat // assumes 60 seats across width...

  • java 1. Write a method header on line three with the following specs: Returns: a boolean...

    java 1. Write a method header on line three with the following specs: Returns: a boolean Name: beTrue Parameters: none public class Main {       {        return true;    } } 2. Write a method header on line two with the following specs: Returns: a String Name: makeCapital Parameters: a String named "name" You should not be writing code on any line other than #2 public class Main {       {    String ans = name.toUpperCase();...

  • in java, finish the method 17: Chapter 8: Handling a number as different types (Method Overloading)...

    in java, finish the method 17: Chapter 8: Handling a number as different types (Method Overloading) J o pulli UCILISIS lule zyBooks catalog Help/FAQ 31.47 Chapter 8: Handling a number as different types (Method Overloading) Write an overloaded method called divide_by_two() that can handle a number between 1-5 as an int, double, or String. • The method should be able to handle the String version with upper or lower case letters in any location in the String. ACTIVITY 31.47.1: Chapter...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • This Exercise contains two classes: ValidateTest and Validate. The Validate class uses try-catch and Regex expressions...

    This Exercise contains two classes: ValidateTest and Validate. The Validate class uses try-catch and Regex expressions in methods to test data passed to it from the ValidateTest program. Please watch the related videos listed in Canvas and finish creating the 3 remaining methods in the class. The regular expression you will need for a Phone number is: "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$" and for an SSN: "^\\d{3}[- ]?\\d{2}[- ]?\\d{4}$" This exercise is meant to be done with the video listed in the...

  • For the code below write a public static main() method in class Student that: - creates...

    For the code below write a public static main() method in class Student that: - creates an ArrayList<Student> object called students - adds 4 new Student objects to the students list, with some made up names and dates - sort the students list by name and display the sorted collection to System.out. use function getCompByName() - sort the students list by enrollment date and display the sorted collection to System.out. use function getCompByDate() import java.util.Comparator;    import java.util.Date;    public...

  • Write a unit test to test the following class. Using Java : //Test only the debit...

    Write a unit test to test the following class. Using Java : //Test only the debit method in the BankAccount. : import java.util.*; public class BankAccount { private String customerName; private double balance; private boolean frozen = false; private BankAccount() { } public BankAccount(String Name, double balance) { customerName = Name; this.balance = balance; } public String getCustomerName() { return customerName; } public double getBalance() { return balance; } public void setDebit(double amount) throws Exception { if (frozen) { throw...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT