Question
practice 14 (dynamic allocated two-dimensional arrays and class) Problem1 dynamic allocated two-dimensional array This program fills and print out the board. The steps are: Declare
practice 14 (dynamic allocated two-dimensional arrays and class)
Problem1 dynamic allocated two-dimensional array
This program fills and print out the board.
The steps are:
Declare an int** variable named board which will be used for dynamical array;
Declare two int variables row and column.
Prompt user to enter the values of row and column;
Dynamically allocates a two-dimensional array large enough to hold that row*column values;
Prompt users to enter the values for the board.
Print out the board.
Problem 2 class (simple program)
Complete the following program:
#include
using namespace std;
//define a class named DayOfYear with two public data members (month and day) and one public function member (function prototype: void output())
int main( )
{
//declare two variables named today and birthday of type DayOfYear.
//assign variable todays member month and member day to be 2 and 15;
//print out todays date (print out member month and member day of variable today using function member of output)
//prompt user to enter their birthdays month and day, and save them in the corresponding members of variable birthday
//print out users birthday (print out member month and member day of variable birthday using function member of output)
//compare variables today and birthday, if they are same, print out Happy Birthday!; otherwise, print out Happy Unbirthday!
return 0;
}
//complete the definition of function member output of class DayOfYear
void DayOfYear::output( )
{
//print out the data members month and day
}
practice 16
Problem 1: Revise Problem 2 of practice 14 to do the following:
1)make members month and day private
2)add new functions:
a.getMonth: void function with one reference parameter which will take the value of member month
b.getDay: void function with one reference parameter which will take the value of member day
c.setMonth: void function with one value parameter newmonth which will be assigned to member month
d.setDay: void function with one value parameter newday, which will be assigned to member day
e.compareDate: bool function with one const reference parameter (say myday) of DayofYear type; return true if members month and day are same as mydays month and day, otherwise, return false.
f.increMonth: increase member month by 1, if it is greater than 12, then set it to be 1
g.increDay: increase member day by 1, if it is greater than corresponding days of member month (assume it is leap year), then set it to be 1 and call increMonth
3)rewrite main function and test all your functions
Problem 2: Revise problem 1 to do the following:
1)Keep members month and day private same
2)Keep functions of getMonth, getDay, setMonth, setDay, increMonth, increDay, and output same as before
3)Add three constructors:
DayofYear(); which is a default constructor and sets member month and day to be 1 and 1.
DayofYear(int m, int d); which sets member month and day to be m and d if m is a valid month and d is a valid day in this month
DayofYear(int m); which sets member month to be m and d to be 1 if m is a valid month.
4)Revise function compareDate to a friend function of class DayofYear with two parameters which are both type DayofYear
5)rewrite main function and test all your functions
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started