Hello everyone, Im decent at RAPTOR but I have a hard time getting started with
ID: 3762430 • Letter: H
Question
Hello everyone, Im decent at RAPTOR but I have a hard time getting started with each assignment. If I can see an example then I can figure it out. I looked at previous posts about this and all I see is program codes and no display of the actual flowchart. Any help is greatly appreciated. Calculator Program Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user. Your program design 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 calculator program. 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, displaying the result, prompting the user to add two more different numbers) until the user enters a sentinel value to end the chosen arithmetic operation. If the user chooses division, do not allow the user to divide by 0. Display an error message to user and ask the user to choose another denominator. You are to submit the following for the assignment: Submit your C++ source code that you generated from RAPTOR with comments added to each line or where necessary to explain program flow. Also submit the RAPTOR file (flowchart) of your working program. Make sure you run it to make sure it is error free and does what it is supposed to. You can use the generate dropdown to create example C++ code based on your working logical flow chart to see what the code would look like. Remember to follow the guidelines of good program design. Make sure to use meaningful variable names and include comments as needed.
Explanation / Answer
Hi,
Below is the solution to your problem:
C++ calculator program:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
//Defining variables and assigning value to them
double num1,num2;
char operation,redo;
cout<<"Welcome to the calculator program "<<endl;
cout<<"***************************************************************"<<endl;
cout<<endl<<endl<<endl;
//Do loop is used so that same program can be used to run multiple times till user presses quit.
do
{
//----receiving the variables from input--------------
cout<<" Please enter an operation that you would like to perform?(+,-,*,/)";
cin>>operation ;
cout<<endl<<endl;
cout<<" Please enter two numbers num1 and num2 (";
cout<<operation<<"):"<<endl<<"1st num:";
cin>>num1;
cout<<"2nd num:" ;
cin>>num2;
cout<<endl;
//switch statement so that the particular operation can be decided
//Based on the operation that is being performed you can choose the operation and perform it.
switch (operation)
{
//calculating the requested operation for user based inputs
case'+':
cout<<"The addition of two numbers ("<<num1<<","<<num2<<"):";
cout<<num1+num2<<endl;
break;
case'-':
cout<<"The substraction of two numbers ("<<num1<<","<<num2<<"):";
cout<<num1-num2<<endl;
break;
case'*':
cout<<"The multiplication of two numbers ("<<num1<<","<<num2<<"):";
cout<<num1*num2<<endl;
break;
case'/':
//If second number is 0 divsion is not possible
cout<<"The division of two numbers ("<<num1<<","<<num2<<"):";
if(num2==0)
{
cout<<"not valid"<<endl;
}
cout<<(num1/num2)<<endl;
break;
default:
cout<<"unknown command"<<endl;
}
//Now again the program prompts the user if he wants to continue or not
cout<<"enter y or Y to continue:";
cin>>redo;
cout<<endl<<endl;
}
//If user types Y or y it will prompt the user again what kind of operation he wants to perform and any other character pressed by user will quit from the program
while(redo=='y'||redo=='Y');
system("pause");
return 0;
}
Flow chart from RAPTOR:
I cannot attach the file that i generated from RAPTOR.So i am providing you the drop box link for the same.
https://www.dropbox.com/s/8v4cqd0i9rpgrga/filename.rap?dl=0
Please see the file and the above code.
Hope that helps...HAPPY ANSWERING!!!!!!!!!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.