CE – Return and Overload in C++
You are going to create a rudimentary calculator.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
#include <iostream>
#include <string>
using namespace std;
// Function Declarations
int getValidMenuOption();
char getvalidExitOption();
int add(int a, int b);
int sub(int a, int b);
int divide(int a, int b);
int multiply(int a, int b);
int modulas(int a, int b);
void display(int ares, int sres, int mres, int dres, int
modre);
double add(double n1, double n2);
double sub(double n1, double n2);
double divide(double n1, double n2);
double multiply(double n1, double n2);
void display(double ares, double sres, double mres, double
dre);
int main() {
//Declaring variables
int choice, a, b;
double n1, n2;
char exitop;
/* This while loop continues to execute
* until the user enters a valid input
*/
while (true) {
//displaying the menu
cout << "\n1 - Integer Math" << endl;
cout << "2 - Double Math" << endl;
cout << "3 - Exit" << endl;
cout << "Enter Choice :";
//getting the choice entered by the user
choice = getValidMenuOption();
//Based on the user choice the corresponding case will be
executed
switch (choice) {
case 1:
{
cout << "Enter two numbers ( seperated by space ):";
cin >> a >> b;
int ares = add(a, b);
int sres = sub(a, b);
int dres = divide(a, b);
int mres = multiply(a, b);
int modres = modulas(a, b);
display(ares, sres, mres, dres, modres);
continue;
}
case 2:
{
cout << "Enter two numbers ( seperated by space ):";
cin >> n1 >> n2;
double ares = add(n1, n2);
double sres = sub(n1, n2);
double dres = divide(n1, n2);
double mres = multiply(n1, n2);
display(ares, sres, mres, dres);
continue;
}
case 3:
{
exitop = getvalidExitOption();
if (exitop == 'y' || exitop == 'Y') {
break;
} else {
continue;
}
}
}
break;
}
return 0;
}
int getValidMenuOption() {
int choice;
while (true) {
cin >> choice;
if (choice < 1 || choice > 3) {
cout << "** Invalid.Must be between 1 and 3 **" <<
endl;
} else {
break;
}
}
return choice;
}
char getvalidExitOption() {
char ch;
while (true) {
cout << "Do you want to exit the program (Y or y/N or
n):";
cin >> ch;
if (ch != 'y' && ch != 'Y' && ch != 'n' &&
ch != 'N') {
cout << "Invalid.Must be either 'Y' or 'y' / 'N' or 'n'"
<< endl;
} else {
break;
}
}
return ch;
}
int add(int a, int b) {
return a + b;
}
int sub(int a, int b) {
return a - b;
}
int divide(int a, int b) {
return a / b;
}
int multiply(int a, int b) {
return a * b;
}
int modulas(int a, int b) {
return a % b;
}
void display(int ares, int sres, int mres, int dres, int modres)
{
cout << "Addition :" << ares << endl;
cout << "Subtraction :" << sres << endl;
cout << "Multiplication :" << mres << endl;
cout << "Division :" << dres << endl;
cout << "Modulas :" << modres << endl;
}
double add(double n1, double n2) {
return n1 + n2;
}
double sub(double n1, double n2) {
return n1 - n2;
}
double divide(double n1, double n2) {
return n1 / n2;
}
double multiply(double n1, double n2) {
return n1 * n2;
}
void display(double ares, double sres, double mres, double dres)
{
cout << "Addition :" << ares << endl;
cout << "Subtraction :" << sres << endl;
cout << "Multiplication :" << mres << endl;
cout << "Division :" << dres << endl;
}
____________________________
Output:
_______________Could you plz rate me well.Thank
You
CE – Return and Overload in C++ You are going to create a rudimentary calculator. The...
C++ Fraction calculator Need help with code, cant use "using namespace std" Objectives Create and use functions. Use a custom library and namespace. Use reference variables as parameters to return values from functions. Create a robust user interface with input error checking. Use exceptions to indicate errors. Resources kishio.h kishio.cpp Assignment requirements You will need eight methods (including main). One is given to you. Their requirements are specified below: menu: The menu function takes no arguments, but returns a char...
The language is C++ for visual studio express 2013 for windows create a TicketManager class and a program that uses the class to sell tickets for a performance at a theater. Here are all the specs. This is an intense program, please follow all instructions carefully. -I am only creating the client program that uses the class and all it's functions -The client program is a menu-driven program that provides the user with box office options for a theater and...
Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++ required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....
C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...
import java.util.Scanner; public class MPGMain { public static void main(String[] args) { Scanner input = new Scanner(System.in); Mileage mileage = new Mileage(); System.out.println("Enter your miles: "); mileage.setMiles(input.nextDouble()); System.out.println("Enter your gallons: "); mileage.setGallons(input.nextDouble()); System.out.printf("MPG : %.2f",mileage.getMPG()); } } public class Mileage { private double miles; private double gallons; public double getMiles()...
Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...
Description: In the main program create a menu system that will allow a user to choose from 3 option. 1. Fraction calculator 2. Grading schema 3. Biggest integer Program #1 Fraction calculator: You will start by prompting the user for two fractions in the main. The inputs should be two strings in the form #/#. You must account for both positive and negative numerators. Therefor -#/# is also a valid input. In a separate function create a program that will...
Given the incomplete program below, write two functions, one called integer and another called decimal. You can use following incomplete program. Your assignment is to supply the necessary missing code: #include #include using namespace std; int integer (….) { //REPLACE THE … WITH THE REQUIRED PARAMETER (A DOUBLE) //WRITE HERE THE CODE TO EXTRACT THE INTEGER AND RETURN IT } double decimal (….) { //REPLACE THE … WITH THE REQUIRED PARAMETER //WRITE HERE THE CODE TO EXTRACT THE DECIMAL PORTION,...
Create a new project called Date In This new project you are going to design a class of Date. This mean that you need to create functions within the class to validate the Date for example: is it a leap year? How many days a months has? How many months are? Create a simple main menu capable of entering a date and validating a date. Instructions • Create a class of Date with attribues and member functions (remember the use...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...