Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 2

Find the error(s) in each of the following and explain how to correct it (them): a. Assume the following prototype is declared in class Time: void ~Time( int ); b. The following is a partial definition of class Time: class Time { public: // function prototypes private: int hour = 0; int minute = 0; int second = 0; }; // end class Time c. Assume the following prototype is declared in class Employee: int Employee( const char *, const char * );

Problem 3

What is the purpose of the scope resolution operator?

Problem 5

Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided. Provide public member functions that perform the following tasks: a. Adding two complex numbers: The real parts are added together and the imaginary parts are added together. b. Subtracting two complex numbers: The real part of the right operand is subtracted from the real part of the left operand, and the imaginary part of the right operand is subtracted from the imaginary part of the left operand. c. Printing complex numbers in the form (a, b), where a is the real part and b is the imaginary part.

Problem 6

(Rational Class) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data of the classthe numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form. For example, the fraction \(\frac{2}{4}\) would be stored in the object as 1 in the numerator and 2 in the denominator. Provide public member functions that perform each of the following tasks: a. Adding two Rational numbers. The result should be stored in reduced form. b. Subtracting two Rational numbers. The result should be stored in reduced form. c. Multiplying two Rational numbers. The result should be stored in reduced form. d. Dividing two Rational numbers. The result should be stored in reduced form. e. Printing Rational numbers in the form a/b, where a is the numerator and b is the denominator. f. Printing Rational numbers in floating-point format.

Problem 11

(Rectangle Class) Create a class Rectangle with attributes length and width, each of which defaults to \(1 .\) Provide member functions that calculate the perimeter and the area of the rectangle. Also, provide set and get functions for the length and width attributes. The set functions should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0.

Problem 14

(HugeInteger Class) Create a class Hugetnteger that uses a 40 -element array of digits to store integers as large as 40 digits each. Provide member functions input, output, add and substract. For comparing HugeInteger objects, provide functions isEqualTo, isNotEqualTo, isGreaterThan, isLessThan, isGreaterThan0rEqualTo and isLessThan0rEqualtoeach of these is a "predicate" function that simply returns TRue if the relationship holds between the two HugeIntegers and returns false if the relationship does not hold. Also, provide a predicate function is zero. If you feel ambitious, provide member functions multiply, divide and modulus.

Problem 15

(Tictactoe Class) Create a class Tictactoe that will enable you to write a complete program to play the game of tic-tac-toe. The class contains as private data a 3 -by-3 two-dimensional array of integers. The constructor should initialize the empty board to all zeros. Allow two human players. Wherever the first player moves, place a 1 in the specified square. Place a 2 wherever the second player moves. Each move must be to an empty square. After each move, determine whether the game has been won or is a draw. If you feel ambitious, modify your program so that the computer makes the moves for one of the players. Also, allow the player to specify whether he or she wants to go first or second. If you feel exceptionally ambitious, develop a program that will play three-dimensional tic-tac-toe on a \(4-b y-4-b y-4\) board. [Caution: This is an extremely challenging project that could take many weeks of effort!]

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks