Data Structure
DuC.vial 20 Answer the following questions 1 Write one or more lines of C++ statements that perform the following initializations (a) Declare a pointer variable called datePtr which points to a Date class type, use dynamic memory allocation to create a 10-element Date array and assign it to the pointer variable datePtr (b) Delete the pointer array datePtr 2 The following code has some errors. Please point out and correct them (there might be more than 1 errors). Note: the use of const data member increment and member function print // This code has some errors. #include
using namespace std: class Increment public: Increment ( int c 0, int i 0) void addIncrement) const count void print) const increment: private: int count: const int increment; Increment: :Increment (int c, int i) increment-i void Increment: :print) cout "count = " using namespace std: #include int main () string s1, s2 ("define") cout In operator prompt user to input a date with format dd/mm/yyyy and then use strtok to separate the numbers and assign them to the data members. In operators you need to output the date with format: Jan 5, 2016 (you may define a 6 Write a class named Date which has three private data: day, month, year monthName[ 12][14] to store the short name of months). Then n program to create an object and call cin and cout. You can user will input correct format. Sample output assume the Enter date in format dd/mm/yyyy: 4/12/2015 The date is: Dec. 4, 2015 7 Define a class called Rational for rational numbers. A rational number is a number that can be represented as the quotient of two integers. For example, 1/2, 3/4, 64/2, and so forth are all rational numbers. Represent rational numbers as two private values of type int, num for the numerator and den for the denominator. The class has a default constructor with default values (mam-0, den 1), a copy constructor, an assignment operator and three friend functions for operator overloading +, > In + operator, the sum of a/b and c/d is (a*d+b'c)bd. In>operator, if the user enter 0 for the denominator, output error message and prompt user to type again (use while loop). In > and assign data for them. Then sum the two numbers and display the results. Sample output Enter two integers: 3 0 Error: the denominator cannot be 0. Try again. Enter two integers: 2 3 Enter two integers: 3-4 (2 bonus marks) Add a private member function with function prototype void normalize() to normalize the values stored so that, after normalization, the denominator is positive and the numerator and denominator are as small as possible. For example, after normalization 4/-8 would be represented the same as -1/2. You must email me your code for this part