Hi everyone! So I'm struggling to finish my course work for a beginners C++ course before midnight June 30th eastern north american time, there are a few questions which I can't figure out so I have resorted to your help :)
Each question should be made in a separate .cpp file, because each is a separate program. The deadline to submit is June 30th at 11:59pm eastern north american time so I know it is short notice and that only leaves you with a day and a half at best to do these. Even if you can complete 90% of this that would be awsome! The questions are below:
1: Write a program that creates an array of 100 string objects. Fill the array by having your program open a (text) file, and read one line of the file into each string until you have filled the array. Display the array using the format âline #: <string>â, where # is the actual line number (you can use the array counter for this value), and <string> is the stored string.
2: Create a makefile for the above exercise that allows the user to type make for a production build of the program, and make debug for a build of the program that includes debugging information.
3: Write a program to manage DVD rental in a âvideoâ rental store. Create an abstract data type that represents a DVD in this store. Consider all the data and operations that may be necessary for the DVD type to work well within a rental management system. Include a print() member function that displays all the information about the DVD. Test your data type by creating an array of 10 DVD instances and filling them using information read from a test input file that you create. Display the DVD information.
4:Write a program in which you create a Hen class. Inside this class, nest a Nest class. Inside Nest, place an Egg class. Each class should have a display() member function. For each class, create a constructor and a destructor that prints an appropriate message when it is called. In main(), create an instance of each class using new, and call the display() function for each one. After calling display(), free the storage using delete.
5: Write a program in which you create a Text class that contains a string object to hold the text of a file. Give it two constructors: a default constructor, and a constructor that takes a string argument that is the name of the file to open. When the second constructor is used, open the file and read the contents of the file into the string member object. Add a member function contents() to return the string so that you can display it. In main(), open a file using Text, and display the contents.
6:Write a program in which you create a const whose value is determined at runtime by reading the time when the program starts (Hint: use the <ctime> standard header). In a separate function, have the program create two arrays of 10 000 doubles. Initialize the first array with sequential integral values starting with 100, and initialize the second array with the same numbers, but in reverse order (i.e., the first array would contain 100, 101, 102⦠while the second array contains 10099, 10098, 10097â¦). Loop through both arrays using a single loop, multiply the corresponding array elements from each array together, and display the result. Read the time when the program completes the multiplication, then compute and display the elapsed time. Do not use inline functions in this program.
7:Rewrite program #1 using an inline function to perform the calculation. In the test plan for this program (actual results section), compare the time required by this program to execute against the time required by the first (non-inline) program.
8:Create a simple class (DoStuff) containing an int, and overload the operator+ as a member function. Also, provide a print() member function that takes an ostream& as an argument and prints to that ostream&. Add a binary operator- and operator+ to the class as member functions. You should be able to use the objects in complex expressions such as a + b â c. Now add the operator++ and operator--, both prefix and postfix versions. Overload the << operator to provide the same functionality as the print() member function. Test the class to show that all requirements work correctly.
9:Write a program that creates a class hierarchy for simple geometry.
Start with a Point class to hold x and y values of a point. Overload the << operator to print point values, and the + and â operators to add and subtract point coordinates (Hint: keep x and y separate in the calculation).
Create a pure abstract base class Shape, which will form the basis of your shapes. The Shape class will contain abstract functions to calculate area and circumference of the shape, plus provide the coordinates (Points) of a rectangle that encloses the shape (a bounding box). These will be overloaded by the derived classes. Create a display() function that will display the name of the class, and all stored information about the class (including area, circumference, and bounding box).
Build the hierarchy by creating the Shape classes Circle, Square, and Triangle. For these derived classes, create default constructors, and constructors whose arguments can initialize the shapes appropriately using the correct number of Point objects (i.e., Circle requires a Point center and a radius, Square requires four Point vertices, while Triangle requires three Point vertices).
In main(), create one instance each of the following: Circle (10, -5) with a radius of 23; Square (5, -5)(-10,7)(4,23)(-6,12); and Triangle(0,0)(10,10)(-15,15). Display the information from each object.
10: Create an inheritance hierarchy of Rodent: Mouse, Gerbil, Hamster, etc. In the base class, provide methods that are common to all Rodents, and refine these in the derived classes to perform different behaviours depending on the specific type of Rodent. Rodent must be created as a pure abstract base class. Create an array of pointers (10) to Rodent, and fill it with different specific types of Rodents. Call your base class methods, and display the results.
11: Using the Standard C++ Library vector as an underlying implementation, create a Set template class that accepts only one of each type of object that you put into it. Make a nested iterator class that supports the âend sentinelâ concept in Unit 16. Write test code for your Set in main(), using both your Set template class and the Standard C++ Library set template to verify that the behaviour is correct.