Description
Course: CSE 165
All the exercises below are selected from the textbook: Thinking in C++ (volume 1).
1. [Exercise 7 on Page 425] Create a class (e.g., myClass) that contains an array of char (e.g., char myArray[100]). Add an inline constructor that uses the Standard C library function memset() to initialize the array to the constructor argument (default this to ‘ ’) (e.g., myClass(char c = ‘ ‘){/* call memset(…) properly */}), and an inline member function called print( ) to print out all the characters in the array. [40 pts]
In main(), do the following:
1) create an object (e.g., myObj) of class myClass
2) call myObj.print(/* any character */) to print out all the characters in myArray.
2. [Exercise 2 on Page 570] Create a simple class (e.g., mySimpleClass) containing an int (e.g., int x) and overload the addition operator (+) and the multiplication operator (*) as two member functions. Also provide a print( ) member function that takes an ostream& (e.g., cout) as an argument (e.g., void print(ostream& out)) and print x to that ostream& (e.g., out << x). [60 pts]
In main(), do the following:
1) create two objects (e.g., a and b) of class mySimpleClass.
2) create another object (e.g., c) of class mySimpleClass and let c = a * a + b * b.
3) call c.print(cout) to print x.
Requirements:
* Usage of spaces, blank lines, indention, and comments for readability.
* Descriptive names of variables, functions, structs, classes, and objects (if any).
* Appropriate usage of structs, classes, and objects (if any).
Penalties:
* Zero if you have possession of a copy of online solutions or work done by someone else.
* 5-point deduction per day late
Reviews
There are no reviews yet.