Try the fastest way to create flashcards
Question

Find the error(s) in the following code:

class findErrors // Line 1
{                // Line 2
    friend int operator*(const int &a,
                         const int &b); // Line 3
    // Returns the object containing the
    // product of the corresponding instance
    // variables of the objects a and b of
    // findError.
public:                           // Line 4
    findErrors(int = 0, int = 0); // Line 5
private:                          // Line 6
    int first;                    // Line 7
    int second;                   // Line 8
};                                // Line 9
double findErrors::operator*(const findErrors &a,
                             const findErrors &b) // Line 10
{                                                 // Line 11
    findErrors temp;                              // Line 12
    temp.first = first * b.first;                 // Line 13
    temp.second = second * b.second;              // Line 14
    return temp;                                  // Line 15
} // Line 16

Solution

Verified
Answered 2 years ago
Answered 2 years ago
Step 1
1 of 3

In friend int operator*(const int& a, const int& b);, the return type as well as the parameters' type should be findErrors, not int. Also, there should only be one parameter.

Create a free account to view solutions

Create a free account to view solutions

Recommended textbook solutions

Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
948 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
872 solutions
Introduction to Algorithms 4th Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

4th EditionISBN: 9780262046305Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
945 solutions
C++ Programming: From Problem Analysis to Program Design 8th Edition by D. S. Malik

C++ Programming: From Problem Analysis to Program Design

8th EditionISBN: 9781337102087D. S. Malik
1,889 solutions

More related questions

1/4

1/7