Info: The next question related to the Exam class whose definition (.h file) is shown below. This Exam class represents a certain student’s test score.
#include <string>
namespace cs31 {
class Exam {
public: Exam ( std::string student, int score = 90 ); bool equal( const Exam & e1, const Exam & e2 ) const; int getScore() const; std::string getStudent() const;
private:
std::string mName; // Exam’s Student name int mScore; // Exam’s Student Score
};
}
1a) Suppose we decide to create a setter named Exam::setScore( int score ) to update the matching appropriate data member. What will its implementation look like in the matching .cpp file?
Select one:
a. void Exam::setScore( int score ) const
{
mScore = score;
}
b. int Exam::setScore( ) const
{
return( mScore );
}
c. void Exam::setScore( int score )
{
mScore = score;
}
d. void setScore( int score )
{
mScore = score;
}
1b) You are working with a partner to build an online grading
system that works with the class Exam shown above. Your partner has
added a new method to the Exam class defined
as:
void Exam::bar( int i )
const;
What do you know from this declaration?
Select one:
a. The Exam instance you use to call this method bar maybe changed
b. A class method cannot be marked const, so this declaration will break the Exam class
c. The Exam instance you use to call this method bar will not be changed, no matter what happens
d. None of the above choices are correct
1c)
You are working with a partner to build an online grading system
that works with the class Exam shown above. Your partner has
defined the function signature: void foo(
Exam & e )
What do you know from this declaration?
Select one:
a. C++ will make a copy of the exam instance you pass to this function foo and use it inside this function foo
b. None of the above choices are correct
c. The Exam instance you pass to this function foo maybe changed by the function
d. The Exam instance you pass to this function foo will not be changed, no matter what happens
1. a)
c. void Exam::setScore( int score
)
{
mScore = score;
}
The function cannot be a const since it is changing the instance variable, so option a and b are wrong. Option c is correct because the implementation of a function must have the class mentioned in the .cpp file
1. b)
c. The Exam instance you use to call this method bar will
not be changed, no matter what happens
A function with the keyword const cannot the object that is used to call it, so option c is the correct option.
1. c)
c. The Exam instance you pass to this function foo maybe
changed by the function
The instance of Exam e is passed by reference using the symbol
&, which indicates that the function may change the instance
inside this function and it wants the change to reflect outside the
function too.
Info: The next question related to the Exam class whose definition (.h file) is shown below....
Given the following class definition in the file Classroom.h, which XXX and YYY complete the corresponding.cpp file? #ifndef CLASSROOM_H #define CLASSROOM_H class Classroom public: void SetNumber(int n); void Printo const; private: int num; }; Tendif #include <iostream using namespace std; XXX void Class Room:: Set Number(int n) { nun: cout << "Number of Class Rooms: << num << endl; include "Classroom.hr vold Classroom: Print( const sinclude "Classroom.cpp" vold Classroom. Print() const #include "Classroom.h" void Class Room::Print) const #include "Classroom.cpp" void...
Requirements I have already build a hpp file for the class architecture, and your job is to implement the specific functions. In order to prevent name conflicts, I have already declared a namespace for payment system. There will be some more details: // username should be a combination of letters and numbers and the length should be in [6,20] // correct: ["Alice1995", "Heart2you", "love2you", "5201314"] // incorrect: ["222@_@222", "12306", "abc12?"] std::string username; // password should be a combination of letters...
This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...
1) In the Quiz class, the foo method has the following API: public void foo( int x, String s) Which method call(s) would be correct assuming both a and y are integer values and assuming each statement is complete? a. Quiz q = new Quiz(); a = q.foo( y, “Maybe?” ); b. Quiz q = new Quiz(); q.foo( 1, “Hmmm!” ); c. Quiz q = new Quiz(); Quiz.foo( y, “You think” ); d. Both b and c 2) In the...
Look at this partial class definition, and then answer questions a - b below: Class Book Private String title Private String author Private String publisher Private Integer copiesSold End Class Write a constructor for this class. The constructor should accept an argument for each of the fields. Write accessor and mutator methods for each field. Look at the following pseudocode class definitions: Class Plant Public Module message() Display "I'm a plant." End Module...
please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...
Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class declaration for Time to complete the questions below: DO NOT WRITE MORE THAN ASKED FOR. class Time private: int hours; int minutes; public: Time(); Time (int , int m = 0); void addMin(int m); void addHr(int h); void reset(int h = 0, int m = 0); Time operator+(const Time & t) const; Time operator-(const Time & t) const; Time operator*(double n) const; friend Time...
Studying for an exam and would like help on the following review question: 17. Consider the following class declaration when answering this question class DB_Arrays { public: DB_Arrays( ); //default constructor. DB_Arrays(const DB_Arrays & Org); //copy constructor. ~DB_Arrays( ); //destructor. void Print_Arrays( ); //prints the contents of both arrays (DB1 followed by DB2) void Insert(const string &, const int & loc); //adds a string to the back of DB1 if loc =1; otherwise string is...
Here is the code from the previous three steps: #include <iostream> using namespace std; class Student { private: //class variables int ID; string firstName,lastName; public: Student(int ID,string firstName,string lastName) //constructor { this->ID=ID; this->firstName=firstName; this->lastName=lastName; } int getID() //getter method { return ID; } virtual string getType() = 0; //pure virtual function virtual void printInfo() //virtual function to print basic details of a student { cout << "Student type: " << getType() << endl; cout << "Student ID: " << ID...
Use main.cpp, Student.h, Student.cpp (written below) and write classes StudentClub and a non-member function find youngest to make main.cpp compile. Put the declaration and definition of find youngest in StudentClub.h and StudentClub.cpp separately. You may not modify provided files and only submit StudentClub.h and StudentClub.cpp. Non-member function find youngest is declared as follows. It returns the names of students who have the youngest age. Note there may exist more than one students who are youngest. std::vector find_youngest(const std::vector member); StudentClub...