C++ Programming Report: Menu-Driven Application Assignment
VerifiedAdded on  2023/01/16
|9
|1833
|76
Report
AI Summary
This report presents a C++ programming assignment focused on developing a menu-driven application. The program allows users to calculate the volume of a cube, the area of a rectangle, and the sum of odd and even numbers within a given range. The report includes the objectives, an introduction to the program's functionality, a flowchart illustrating the program's logic, and the complete C++ source code. The code utilizes functions for calculating cube volume, rectangle area (with default arguments), and recursive functions for computing the sum of odd and even numbers. The report also details the results obtained from executing the program, including screenshots of the output, and a discussion of the program's behavior and the outcomes of various test cases. Finally, the report provides a list of references used for the assignment. This report showcases the application of fundamental C++ concepts such as loops, conditional statements, functions, and recursion to solve practical problems.

Assignment Report
Lab Number:
Title:
Course:
Instructor:
Lab Number:
Title:
Course:
Instructor:
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Report
1. Objectives
The main aim of this assignment is to test the C Programming skill. This assignment test
the understanding of while loop, if else statement, normal and recursive functions etc.
2. Introductions
The task of the assignment is to develop a C++ program that helps the user to perform the
followings task. The program helps the user to determine the volume of the cube, area of the
rectangle and to determine the sum of odd and even numbers between 1 and n. To perform this
task the program displays the menu continuously until the user wishes to quit. Each menu item
provides the option to perform a task. After displaying menu, the user is prompted to enter the
option. If the user choose 1, the application prompts the user to enter the length of the cube, then
the application computes the volume of the cube and displays it. If the user choose 2, the
application prompts the user to enter the width and height of the rectangle, then the application
calculates the area of the rectangle and displays the result. If the user chooses the option 3, the
application prompt the user to enter the positive integer n, the application computes the sum of
odd numbers between 1 and n and then displays the sum. If the user chooses the option 4, the
application prompt the user to enter the positive integer n, the application computes the sum of
even numbers between 1 and n and then displays the sum. If the user chooses the option 5, the
number of times the menu is executed is displayed and the application quits.
To develop the program 4 functions are developed
i) Cube_Volume- This function receives the height of the cube as its parameter and
returns the volume of the cube
ii) Rectangle_Area- This function receives the width and height of the rectangle as its
parameter and returns the area of the rectangle. This function takes the default
arguments 1 and 2 which is used when negative value is entered for width and height.
iii) Recursive_OddSum- This recursive function takes the positive integer n as its
parameter and returns the sum of odd numbers between 1 and n
iv) Recursive_EvenSum- This recursive function takes the positive integer n as its
parameter and returns the sum of even numbers between 1 and n
v) Print_Menu- This function neither takes any argument as its parameter nor returns
any data. This function is used to output the list of menu option.
1. Objectives
The main aim of this assignment is to test the C Programming skill. This assignment test
the understanding of while loop, if else statement, normal and recursive functions etc.
2. Introductions
The task of the assignment is to develop a C++ program that helps the user to perform the
followings task. The program helps the user to determine the volume of the cube, area of the
rectangle and to determine the sum of odd and even numbers between 1 and n. To perform this
task the program displays the menu continuously until the user wishes to quit. Each menu item
provides the option to perform a task. After displaying menu, the user is prompted to enter the
option. If the user choose 1, the application prompts the user to enter the length of the cube, then
the application computes the volume of the cube and displays it. If the user choose 2, the
application prompts the user to enter the width and height of the rectangle, then the application
calculates the area of the rectangle and displays the result. If the user chooses the option 3, the
application prompt the user to enter the positive integer n, the application computes the sum of
odd numbers between 1 and n and then displays the sum. If the user chooses the option 4, the
application prompt the user to enter the positive integer n, the application computes the sum of
even numbers between 1 and n and then displays the sum. If the user chooses the option 5, the
number of times the menu is executed is displayed and the application quits.
To develop the program 4 functions are developed
i) Cube_Volume- This function receives the height of the cube as its parameter and
returns the volume of the cube
ii) Rectangle_Area- This function receives the width and height of the rectangle as its
parameter and returns the area of the rectangle. This function takes the default
arguments 1 and 2 which is used when negative value is entered for width and height.
iii) Recursive_OddSum- This recursive function takes the positive integer n as its
parameter and returns the sum of odd numbers between 1 and n
iv) Recursive_EvenSum- This recursive function takes the positive integer n as its
parameter and returns the sum of even numbers between 1 and n
v) Print_Menu- This function neither takes any argument as its parameter nor returns
any data. This function is used to output the list of menu option.

3. Flowchart
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

4. Code
#include <iostream>
using namespace std;
// This function is used to calculate the volume of the cube
float Cube_Volume(float height){
return height*height*height;
}
// This function is used to calculate the area of the rectangle.
// This function has the default arguments for width and height
double Rectangle_Area(double width=1, double height=2){
return width*height;
}
// This function is used to calculate the sum of odd numbers from 1 to n
int Recursive_OddSum(int n){
// if the number is less than or equal to 0 return 0
if (n<=0){
return 0;
}
// check if the number is odd
if(n%2!=0){
// add n with the Recursive_OddSum with n decremented by 1
return n+Recursive_OddSum(n-1);
}
// return the Recursive_OddSum with n decremented by 1
return Recursive_OddSum(n-1);
}
// This function is used to calculate the sum of even numbers from 1 to n
int Recursive_EvenSum(int n){
// if the number is less than or equal to 0 return 0
if (n<=0){
return 0;
}
// check if the number is even
if(n%2==0){
// add n with the Recursive_EvenSum with n decremented by 1
return n+Recursive_EvenSum(n-1);
}
// return the Recursive_EvenSum with n decremented by 1
#include <iostream>
using namespace std;
// This function is used to calculate the volume of the cube
float Cube_Volume(float height){
return height*height*height;
}
// This function is used to calculate the area of the rectangle.
// This function has the default arguments for width and height
double Rectangle_Area(double width=1, double height=2){
return width*height;
}
// This function is used to calculate the sum of odd numbers from 1 to n
int Recursive_OddSum(int n){
// if the number is less than or equal to 0 return 0
if (n<=0){
return 0;
}
// check if the number is odd
if(n%2!=0){
// add n with the Recursive_OddSum with n decremented by 1
return n+Recursive_OddSum(n-1);
}
// return the Recursive_OddSum with n decremented by 1
return Recursive_OddSum(n-1);
}
// This function is used to calculate the sum of even numbers from 1 to n
int Recursive_EvenSum(int n){
// if the number is less than or equal to 0 return 0
if (n<=0){
return 0;
}
// check if the number is even
if(n%2==0){
// add n with the Recursive_EvenSum with n decremented by 1
return n+Recursive_EvenSum(n-1);
}
// return the Recursive_EvenSum with n decremented by 1
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

return Recursive_EvenSum(n-1);
}
// This function is used to calculate the factorial of the given positive number
int Factorial(int n){
// variable to store the factorial number
int factorial_number=1;
// loop for the number from 1 to n
for(int i=1;i<=n;i++){
// update the factorial number by multiplying with i
factorial_number=factorial_number*i;
}
// return the factorial number
return factorial_number;
}
// This function is used to display the menu
void Print_Menu(){
cout<<"Main Menu"<<endl;
cout<<"---------------------------------------"<<endl;
cout<<"1. Cube Volume"<<endl;
cout<<"2. Rectangle Area"<<endl;
cout<<"3. Recursive Odd Sum"<<endl;
cout<<"4. Recursive Even Sum"<<endl;
cout<<"5. Exit"<<endl;
}
int main()
{
// variable to store the number of times the menu is executed
int menuExecutedCount=0;
// variable to store the option
int option=1;
// loop until the user choose the option 5 to exit
while(option!=5){
// display the menu
Print_Menu();
// prompt and get the user option
cout<<"Enter your option: ";
cin>>option;
}
// This function is used to calculate the factorial of the given positive number
int Factorial(int n){
// variable to store the factorial number
int factorial_number=1;
// loop for the number from 1 to n
for(int i=1;i<=n;i++){
// update the factorial number by multiplying with i
factorial_number=factorial_number*i;
}
// return the factorial number
return factorial_number;
}
// This function is used to display the menu
void Print_Menu(){
cout<<"Main Menu"<<endl;
cout<<"---------------------------------------"<<endl;
cout<<"1. Cube Volume"<<endl;
cout<<"2. Rectangle Area"<<endl;
cout<<"3. Recursive Odd Sum"<<endl;
cout<<"4. Recursive Even Sum"<<endl;
cout<<"5. Exit"<<endl;
}
int main()
{
// variable to store the number of times the menu is executed
int menuExecutedCount=0;
// variable to store the option
int option=1;
// loop until the user choose the option 5 to exit
while(option!=5){
// display the menu
Print_Menu();
// prompt and get the user option
cout<<"Enter your option: ";
cin>>option;

// increment the menu execution count by 1
menuExecutedCount++;
// if the option is 1
if(option==1){
float length;
// prompt and get the length of the cube
cout<<"Enter the length of the cube: ";
cin>>length;
// display the volume of the cube
cout<<"The volume of the cube is "<<Cube_Volume(length)<<endl;
}
else if(option==2){
double width, height, area ;
// prompt and get the width of the rectangle
cout<<"Enter the width of the rectangle: ";
cin>>width;
// prompt and get the height of the rectangle
cout<<"Enter the height of the rectangle: ";
cin>>height;
// if the width is negative
if(width<0){
// call the Rectangle_Area() with no arguments
area=Rectangle_Area();
}
// if the height is negative
else if(height<0){
// call the Rectangle_Area() with one arguments i.e. width
area=Rectangle_Area(width);
}
else{
// call the Rectangle_Area() with rectangle width and height
area=Rectangle_Area(width, height);
}
// display the area of the rectangle
cout<<"The area of the rectangle is "<<area<<endl;
}
else if(option==3){
int n;
// prompt and get the positive integer n
cout<<"Enter a positive integer n: ";
menuExecutedCount++;
// if the option is 1
if(option==1){
float length;
// prompt and get the length of the cube
cout<<"Enter the length of the cube: ";
cin>>length;
// display the volume of the cube
cout<<"The volume of the cube is "<<Cube_Volume(length)<<endl;
}
else if(option==2){
double width, height, area ;
// prompt and get the width of the rectangle
cout<<"Enter the width of the rectangle: ";
cin>>width;
// prompt and get the height of the rectangle
cout<<"Enter the height of the rectangle: ";
cin>>height;
// if the width is negative
if(width<0){
// call the Rectangle_Area() with no arguments
area=Rectangle_Area();
}
// if the height is negative
else if(height<0){
// call the Rectangle_Area() with one arguments i.e. width
area=Rectangle_Area(width);
}
else{
// call the Rectangle_Area() with rectangle width and height
area=Rectangle_Area(width, height);
}
// display the area of the rectangle
cout<<"The area of the rectangle is "<<area<<endl;
}
else if(option==3){
int n;
// prompt and get the positive integer n
cout<<"Enter a positive integer n: ";
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

cin>> n;
// determine and display the sum of odd number from 1 to n
cout << "The sum of odd numbers from 1 to "<< n <<" is
"<<Recursive_OddSum(n)<<endl;
}
else if(option==4){
int n;
// prompt and get the positive integer n
cout<<"Enter a positive integer n: ";
cin>> n;
// determine and display the sum of even number from 1 to n
cout << "The sum of even numbers from 1 to "<< n <<" is
"<<Recursive_EvenSum(n)<<endl;
}
else if(option==5){
// display the number of times the menu executed
cout<<"Number of times the menu executed is "<< menuExecutedCount <<endl;
}
else{
// display the option is invalid
cout<<"Invalid Option."<<endl;
}
cout<<endl;
}
cout<<"Application is Exiting.. "<<endl;
return 0;
}
5. Result & Discussion
On executing the program, the application displays the menu on choosing the option 1,
the application prompts to enter the length of the cube on entering 10.2, the Cube_Volume() is
called, the determined the volume of the cube 1061.21 is displayed to the user. Now the
application displays the menu again, on choosing the option 2, and entering 4.2 and -2.1 as the
width and height of the rectangle, the application notices height as negative hence only the width
is passed to the function Rectangle_Area() and the determined area 8.4 is displayed to the user.
Now the application displays the menu again on choosing option 3 and entering 10 as positive
integer displays 25 as the sum of odd numbers between 1 and 10. Now the application displays
the menu again on choosing option 4 and entering 10 as positive integer displays 30 as the sum
of even numbers between 1 and 10. The application again displays menu on choosing option 5,
// determine and display the sum of odd number from 1 to n
cout << "The sum of odd numbers from 1 to "<< n <<" is
"<<Recursive_OddSum(n)<<endl;
}
else if(option==4){
int n;
// prompt and get the positive integer n
cout<<"Enter a positive integer n: ";
cin>> n;
// determine and display the sum of even number from 1 to n
cout << "The sum of even numbers from 1 to "<< n <<" is
"<<Recursive_EvenSum(n)<<endl;
}
else if(option==5){
// display the number of times the menu executed
cout<<"Number of times the menu executed is "<< menuExecutedCount <<endl;
}
else{
// display the option is invalid
cout<<"Invalid Option."<<endl;
}
cout<<endl;
}
cout<<"Application is Exiting.. "<<endl;
return 0;
}
5. Result & Discussion
On executing the program, the application displays the menu on choosing the option 1,
the application prompts to enter the length of the cube on entering 10.2, the Cube_Volume() is
called, the determined the volume of the cube 1061.21 is displayed to the user. Now the
application displays the menu again, on choosing the option 2, and entering 4.2 and -2.1 as the
width and height of the rectangle, the application notices height as negative hence only the width
is passed to the function Rectangle_Area() and the determined area 8.4 is displayed to the user.
Now the application displays the menu again on choosing option 3 and entering 10 as positive
integer displays 25 as the sum of odd numbers between 1 and 10. Now the application displays
the menu again on choosing option 4 and entering 10 as positive integer displays 30 as the sum
of even numbers between 1 and 10. The application again displays menu on choosing option 5,
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

the application displays 5 times the menu is executed and the application quits. The screenshot
below shows the execution of the program.
below shows the execution of the program.

6. References:
Davis, Stephen R. Beginning Programming with C++ For Dummies. Hoboken, NJ: Wiley
Publishing, Inc, 2010. Print.
Stroustrup, Bjarne. The C++ Programming Language, Upper Saddle River, NJ: Addison
Wesley, 2013. Print.
Sexton, Conor. C++ Programming Made Simple. Woburn, MA: Made Simple Books, 2012.
Print.
Oliveira, Carlos. Practical C++ Financial Programming. Boston, MA: APress, 2015. Print.
McGrath, Mike. C++ Programming. Warwickshire, UK: Easy Steps, 2011. Print.
Kormanyos, Christopher. Real-Time C++. Berlin, Germany: Springer, 2018. Print.
Davis, Stephen R. Beginning Programming with C++ For Dummies. Hoboken, NJ: Wiley
Publishing, Inc, 2010. Print.
Stroustrup, Bjarne. The C++ Programming Language, Upper Saddle River, NJ: Addison
Wesley, 2013. Print.
Sexton, Conor. C++ Programming Made Simple. Woburn, MA: Made Simple Books, 2012.
Print.
Oliveira, Carlos. Practical C++ Financial Programming. Boston, MA: APress, 2015. Print.
McGrath, Mike. C++ Programming. Warwickshire, UK: Easy Steps, 2011. Print.
Kormanyos, Christopher. Real-Time C++. Berlin, Germany: Springer, 2018. Print.
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 9
Related Documents
Your All-in-One AI-Powered Toolkit for Academic Success.
 +13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.





