Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Preparation for Assignment #0 (Review of Functions in C++) Objectives: The main objective of this lab is to help students prepare for assignment #0 (the

image text in transcribedimage text in transcribed

Preparation for Assignment #0 (Review of Functions in C++) Objectives: The main objective of this lab is to help students prepare for assignment #0 (the welcome assignment). Students will review some of the concepts related to functions in C++ which they learned in the pre-requisite class or equivalent. Descriptions: Assume you are volunteering to help at the Norfolk Public Schools (NPS). While volunteering in an elementary art class, you decided to write a C++ program to help the teacher to solve the "box problem". The teacher usually gives the students a flat piece of cardboard of 100 square inches to make an open box by cutting a square from each corner and folding the sides (see the Figure below). The students' objective is to determine the dimensions of the cardboard (the length and width) and the length of the side square to be cut from the corners so that the resulting box is of maximum volume. CHIR Craft class Figure: cardboard box Sample Output (first run): Enter the area of the board : 70 Length of the cardboard to maximize the volume: 8.366 Width of the cardboard to maximize the volume : 8.366 Length of the box with maximum volume : 5.578 Width of the box with maximum volume : 5.579 Height of the box with maximum volume : 1.394 Maximum Volume: 43.382 Sample Output (second run): Enter the area of the board: 100 Length of the cardboard to maximize the volume : 10.000 Width of the cardboard to maximize the volume : 10.000 Length of the box with maximum volume : 6.666 Width of the box with maximum volume : 6.666 Height of the box with maximum volume: 1.667 Maximum Volume: 74.074 Task-A: You are provided with a program in the cardboardBox.cpp file. The program compiles with no errors, and it runs perfectly. The program prompts the user to enter the area of the flat card-board. The program then outputs the length and width of the cardboard and the length of the side of the square to be cut from the corner so that the resulting box is of maximum volume. The program also calculates the maximum volume. Finally, the program calculates the answer to three decimal places. The program in the cardboardBox.cpp file works perfectly, but it is ugly and harder to understand than it should be. That is because the program was written without functions other than the main () function. Your task for this lab exercise is to change/modify the provided program so that it has the exact same functionality, but multiple functions in addition to the main () function. In particular, your program should include the following function: A function named maxVolume () which takes as input the length and width of the cardboard and returns the side of the square that should be cut to maximize the volume. The function also returns the maximum volume. Can you locate the piece of code which can be replaced by this function? Show this portion to your teaching assistant. Declare, implement and call the function. Show your progress to the teaching assistant. Task-B: Can you simplify the program further by proposing more functions? What are the name of these functions? Discuss it with your TA. Example: A function name is min () - which finds the minimum side of the box. The function receives the box length and width as parameters, and returns the minimum of them. Can you locate the piece of code which can be replaced by this function? Declare, implement and call the function. Show your progress to the teaching assistant. Do you suggest using other functions to simplify the code further? Discuss your answer for this question with the students who are setting next to you, and discuss it with your teaching assistant. Preparation for Assignment #0 (Review of Functions in C++) Objectives: The main objective of this lab is to help students prepare for assignment #0 (the welcome assignment). Students will review some of the concepts related to functions in C++ which they learned in the pre-requisite class or equivalent. Descriptions: Assume you are volunteering to help at the Norfolk Public Schools (NPS). While volunteering in an elementary art class, you decided to write a C++ program to help the teacher to solve the "box problem". The teacher usually gives the students a flat piece of cardboard of 100 square inches to make an open box by cutting a square from each corner and folding the sides (see the Figure below). The students' objective is to determine the dimensions of the cardboard (the length and width) and the length of the side square to be cut from the corners so that the resulting box is of maximum volume. CHIR Craft class Figure: cardboard box Sample Output (first run): Enter the area of the board : 70 Length of the cardboard to maximize the volume: 8.366 Width of the cardboard to maximize the volume : 8.366 Length of the box with maximum volume : 5.578 Width of the box with maximum volume : 5.579 Height of the box with maximum volume : 1.394 Maximum Volume: 43.382 Sample Output (second run): Enter the area of the board: 100 Length of the cardboard to maximize the volume : 10.000 Width of the cardboard to maximize the volume : 10.000 Length of the box with maximum volume : 6.666 Width of the box with maximum volume : 6.666 Height of the box with maximum volume: 1.667 Maximum Volume: 74.074 Task-A: You are provided with a program in the cardboardBox.cpp file. The program compiles with no errors, and it runs perfectly. The program prompts the user to enter the area of the flat card-board. The program then outputs the length and width of the cardboard and the length of the side of the square to be cut from the corner so that the resulting box is of maximum volume. The program also calculates the maximum volume. Finally, the program calculates the answer to three decimal places. The program in the cardboardBox.cpp file works perfectly, but it is ugly and harder to understand than it should be. That is because the program was written without functions other than the main () function. Your task for this lab exercise is to change/modify the provided program so that it has the exact same functionality, but multiple functions in addition to the main () function. In particular, your program should include the following function: A function named maxVolume () which takes as input the length and width of the cardboard and returns the side of the square that should be cut to maximize the volume. The function also returns the maximum volume. Can you locate the piece of code which can be replaced by this function? Show this portion to your teaching assistant. Declare, implement and call the function. Show your progress to the teaching assistant. Task-B: Can you simplify the program further by proposing more functions? What are the name of these functions? Discuss it with your TA. Example: A function name is min () - which finds the minimum side of the box. The function receives the box length and width as parameters, and returns the minimum of them. Can you locate the piece of code which can be replaced by this function? Declare, implement and call the function. Show your progress to the teaching assistant. Do you suggest using other functions to simplify the code further? Discuss your answer for this question with the students who are setting next to you, and discuss it with your teaching assistant

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

need a template of proforma for a gas station.

Answered: 1 week ago