Question

C++ Questions. Question 1 What would the function prototype in the class declaration for the following...

C++ Questions.

Question 1

What would the function prototype in the class declaration for the following member function look like?

void Fractions::showData()
{
        if((num < 0 && denom < 0) || denom < 0)
        {
                num = -num;
                denom = -denom;
        }
        cout << num << "/" << denom << endl;
}

Question 2

What would the function header of the following member function prototype in class Fractions be?

Fractions operator+(const Fractions &f2);

Question 3

What would the function prototype in the class declaration for the following friend function look like?

int addDay(const Date& a, const Date& b)
{
 return(a.day + b.day);
}

Question 4

What would the destructor prototype for a Book class look like?

Question 5

What would be the missing line in the following mutator function?

class Date{
private:
     int day;
public:
     void setDay(int);
};

void Date::setDay(int day){
     _______________________
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1:
void showData();
Answer 2:

Fractions Fractions :: operator+(const Date &a,const Date &b){
}
Answer 3:

//we use friend keyword
friend int addDay(const Date &a,const Date &b);
Answer 4:
~Book()
// destructor name will be same as class name
//prefixed with ~
Answer 5:
void Date::setDay(int day){
   *this->day=day;
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
C++ Questions. Question 1 What would the function prototype in the class declaration for the following...
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
  • Refer to this header file: // Fraction class // This class represents a fraction a /...

    Refer to this header file: // Fraction class // This class represents a fraction a / b class Fraction { public: // Constructors Fraction(); // sets numerator to 1 and denominator to 1 Fraction(int num, int denom); // Setters void setNumerator(int num); void setDenominator(int denom); // getters int getNumerator()const {return num;} int getDenominator()const {return denom;} double getDecimal(){return static_cast<double> num / denom;} private: int num, denom; }; 1.Write the code for the non-member overloaded << operator that will display all of...

  • Write a class declaration section for each of the following specifications. Include a prototype for a...

    Write a class declaration section for each of the following specifications. Include a prototype for a constructor and a member function named showData() that can be used to display data member values. a. A class named Time that has integer data members named secs, mins, and hours b. A class named Date that has integer data members named month, day, and year c. A class named Circle that has integer data members named xcenter and ycenter and a double-precision data...

  • CO 3) Demonstrate encapsulation by creating a declaration file from the following UML diagram: (Note) The...

    CO 3) Demonstrate encapsulation by creating a declaration file from the following UML diagram: (Note) The declaration file is the header file (.h file) and implementation file is the .cpp file. Date 0 - num Date: static int - day: int - month: int - year int +Date0 +Date(int, int, int) +Date(Date &) +Date0 +get Day0: int +setDay (nt): void +getMonth int +setMonth (int): void +getYear int +setYear(int) void +dis play Date0: void

  • The class dateType is designed to implement the date in a program, but the member function...

    The class dateType is designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the data members. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and the year are checked before storing the date into the data members. Add a function member, isLeapYear, to check whether a year is a leap...

  • The rest of question 4: object. Make sure that the implementation of class Employee2 includes all...

    The rest of question 4: object. Make sure that the implementation of class Employee2 includes all necessary revisions to all members functions that appeared in class Employee implementation. Heres a link for the class Employee: http://www.cs117.ghriga.com/blog/2017/10/07/practice-4/ de the program and determine its output if the user enters-2 B) Trace the program and determine its output if the u C) Trace the program and determine its output if the ts D) Trace the program and determine its output if the user...

  • Having to repost this as the last answer wasn't functional. Please help In the following program...

    Having to repost this as the last answer wasn't functional. Please help In the following program written in C++, I am having an issue that I cannot get the reducdedForm function in the Rational.cpp file to work. I cant figure out how to get this to work correctly, so the program will take what a user enters for fractions, and does the appropriate arithmetic to the two fractions and simplifies the answer. Rational.h class Rational { private: int num; int...

  • 1.) Add a data member, currentTime into the DataType.h 2.) Add a member function, GetCurrentTime(). Modify...

    1.) Add a data member, currentTime into the DataType.h 2.) Add a member function, GetCurrentTime(). Modify the initialize function. ESIGN PAGE LAYOUT REFERENCES an-E4_]Ka"!Aa.le' | =.=-'E- 恒栏1순↓ | T Font Paragraph // To declare a class for the Date ADT // This is the header file DateType.h class DateType public: void Initialize (int newMonth, int newDay, int newYear) int GetYear) const; int GetMonth() const int GetDay) const private: int year; int month; int day; search

  • How do I pass values to this function? class DynIntQueue { struct QueueNode { int value;...

    How do I pass values to this function? class DynIntQueue { struct QueueNode { int value; QueueNode *next; QueueNode(int value1, QueueNode *next1 = nullptr) { value = value1; next = next1; } }; // These track the front and rear of the queue QueueNode *front; QueueNode *rear; public: // Constructor and Destructor DynIntQueue(); ~DynIntQueue(); // Member functions void enqueue(int); void dequeue(int &); bool isEmpty() const; void clear(); }; main #include <iostream> #include "DynIntQueue.h" using namespace std; int main() {DynIntQueue list;...

  • The following program contains the definition of a class called List, a class called Date and...

    The following program contains the definition of a class called List, a class called Date and a main program. Create a template out of the List class so that it can contain not just integers which is how it is now, but any data type, including user defined data types, such as objects of Date class. The main program is given so that you will know what to test your template with. It first creates a List of integers and...

  • QUESTION 1 Using the following declarations and a member of the Array class, int [ ]...

    QUESTION 1 Using the following declarations and a member of the Array class, int [ ] bArray = new int [10]; int location; Using a method in the Array class, write a statement that would change the order of the elements in the bArray array. The contents of the first cell should hold what was in the last cell. The second cell should hold what was in the next to last cell. __________________________ HINT: You must write the full statement...

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