Using Multidimensional Arrays Summary In this lab, you will complete a C++ progr
ID: 3864389 • Letter: U
Question
Using Multidimensional Arrays
Summary
In this lab, you will complete a C++ program that uses a two-dimensional array to store data for the Building Block Day Care Center. The day care center charges varying weekly rates depending on the age of the child and the number of days per week the child attends. The program should allow the user to enter the age of the child and the number of days per week the child will be at the day care center. The program should output the appropriate weekly rate.
The file provided for this lab contains all of the necessary variable declarations, except the two-dimensional array. You need to write the input statements and the code that initializes the two-dimensional array, determines the weekly rate, and prints the weekly rate. Comments in the code tell you where to write your statements. Weekly rates can be found in the provided table.
Instructions
Declare and initialize the two-dimensional array.
Write the C++ statements that retrieve the age of the child and the number of days the child will be at the day care center.
Determine and print the weekly rate.
Execute the program by clicking the "Run Code" button at the bottom of the screen.
_____________________________________
#include <iostream>
using namespace std;
int main()
{
// Declare two dimensional array here
// Declare other variables
int numDays;
int age;
int QUIT = 99;
// This is the work done in the getReady() function
// Perform a priming read to get the age of the child
while(age != QUIT)
{
// This is the work done in the determineRateCharge() function
// Ask the user to enter the number of days
// Print the weekly rate
// Ask the user to enter the next child's age
}
// This is the work done in the finish() function
cout << "End of program" << endl;
return 0;
} // End of main() function
Rates 1 day 2 days 3 days 4 days 5 days 0 30.00 60.00 88.00 115.00 140.00 1 yr 26.00 52.00 70.00 96.00 120.00 2 yrs 24.00 46.00 67.00 89.00 110.00 3 yrs 22.00 40.00 60.00 75.00 88.00 4 + yrs 20.00 35.00 50.00 66.00 84.00Explanation / Answer
// C++ code
#include <iostream>
using namespace std;
int main()
{
int rates[5][5]={{30,60,88,115,140},
{26,52,70,96,120},
{24,46,67,89,110},
{22,40,60,75,88},
{20,35,50,66,84}
};
int weeklyRate;
int numDays;
int age;
int QUIT = 99;
cout << " Enter age of child or 99 to quit: "<<endl;
cin >> age;
while(age != QUIT)
{
cout << "Enter number of Days(1-5): "<<endl;
cin >> numDays;
if(age>4) // Because it doesn't matter the age of children after 4 year
age=4;
weeklyRate = rates[age][numDays-1];
cout<<"Weekly rate for the children is "<<weeklyRate<<endl;
cout << " Enter age of child or 99 to quit: "<<endl;
cin>>age;
}
cout << "End of program" << endl;
return 0;
}
/*
output:
Enter age of child or 99 to quit:
3
Enter number of Days(1-5):
2
Weekly rate for the children is 40
Enter age of child or 99 to quit:
4
Enter number of Days(1-5):
3
Weekly rate for the children is 50
Enter age of child or 99 to quit:
1
Enter number of Days(1-5):
2
Weekly rate for the children is 52
Enter age of child or 99 to quit:
5
Enter number of Days(1-5):
3
Weekly rate for the children is 50
Enter age of child or 99 to quit:
3
Enter number of Days(1-5):
4
Weekly rate for the children is 75
Enter age of child or 99 to quit:
99
End of program
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.