Question

In: Computer Science

handwriten code for calculate button be able to delcare varables and name constants,use parse to capture...

handwriten code for calculate button be able to delcare varables and name constants,use parse to capture input use formulas in assignment statments,and display formated output on a form

Solutions

Expert Solution

Note :- This code is written in C++ program.

1)It will take arguments through command line, two operands

2) It will parse the arguments stored in argv to get the operation ( + , - , * , / ) that is to be performed.

3) And then it will convert the String to Integer (stoi function)  to do the arithmetic operation.

4) Final Result will be displayed.

--------------------------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>
#include <string>
using namespace std;

main (int argc, char **argv)
{
std::string token;
size_t pos = 0;
std::string inputStr;
std::string delimiterPlus = "+";
std::string delimiterSub = "-";
std::string delimiterMul = "*";
std::string delimiterDiv = "/";
int FinalResult = 0;
int opr1,opr2=0;
bool operatorFlag = false;
  
cout << "You have entered " << argc << " arguments:" << "\n";

for (int i = 0; i < argc; ++i)
{
cout << "argv= "<<argv[i] << "\n";
inputStr = argv[i];
}


//Addition of 2 numbers
while ((pos = inputStr.find (delimiterPlus)) != std::string::npos)
{
//int opr1,opr2;
token = inputStr.substr (0, pos);
//std::cout << "token Plus=" <<token << std::endl;
opr1=stoi(token);
operatorFlag = true;
inputStr.erase (0, pos + delimiterPlus.length ());
}
//cout << "LastInput Plus=" << inputStr << std::endl;
opr2=stoi(inputStr);
  
if(operatorFlag){
FinalResult = opr1 + opr2;
operatorFlag = false;
}
  
//Substraction of two numbers
while ((pos = inputStr.find (delimiterSub)) != std::string::npos)
{
token = inputStr.substr (0, pos);
//std::cout << "token Sub=" <<token << std::endl;
opr1=stoi(token);
operatorFlag = true;
inputStr.erase (0, pos + delimiterSub.length ());
}
  
// cout << "Opr1 Sub=" << opr1 << std::endl;
  
// cout << "LastInput Sub=" << inputStr << std::endl;
opr2=stoi(inputStr);
  
if(operatorFlag){
FinalResult = opr1 - opr2;
operatorFlag = false;
}
      
//Multiplication of two numbers
while ((pos = inputStr.find (delimiterMul)) != std::string::npos)
{
token = inputStr.substr (0, pos);
// std::cout << "token mul=" <<token << std::endl;
opr1=stoi(token);
operatorFlag = true;
inputStr.erase (0, pos + delimiterMul.length ());
}
  
//cout << "Opr1 mul=" << opr1 << std::endl;
  
//cout << "LastInput mul=" << inputStr << std::endl;
opr2=stoi(inputStr);
  
if(operatorFlag){
FinalResult = opr1 * opr2;
operatorFlag = false;
}
  
//Division of two numbers
while ((pos = inputStr.find (delimiterDiv)) != std::string::npos)
{
token = inputStr.substr (0, pos);
//std::cout << "token Div=" <<token << std::endl;
opr1=stoi(token);
operatorFlag = true;
inputStr.erase (0, pos + delimiterDiv.length ());
}

// cout << "Opr1 Div=" << opr1 << std::endl;
  
//cout << "LastInput Div=" << inputStr << std::endl;
opr2=stoi(inputStr);
  
if(operatorFlag){
FinalResult = opr1/opr2;
operatorFlag = false;
}

  
cout<<"Final Result= " << FinalResult <<std::endl;
  
return 0;
}


Related Solutions

Parse string java code Write a recursive program that can calculate the value of a given...
Parse string java code Write a recursive program that can calculate the value of a given polynomial in a string, which is not more than the tenth order, for the given x. The polynomial will be given in the following format and should display the value of the polynomial for spaced-out x Using index of for -/+
My Javascript code isn't working (when i press calculate button) - what's wrong with it ?...
My Javascript code isn't working (when i press calculate button) - what's wrong with it ? Car Rental Enter Number of Rental Days: Select Car Type: onclick= "priceofcar = 50;"/> Compact onclick= "priceofcar = 60;"/> Economy onclick= "priceofcar = 70;"/> Intermediate Select Loss Damage Waiver onclick= "damagewaiver='yes'"/> Yes onclick= "damagewaiver='no'"/> No damagewaiver = boxDays.value * 25;} else if (damagewaiver == No) { damagewaiver = 0; }/> Select Roadside Issues Coverage: onclick= "issuescoverage='yes'"/> Yes onclick= "issuescoverage='no'"/> No issuescoverage = boxDays.value *...
using java, parse a text file to be able to list the word(s) with the highest...
using java, parse a text file to be able to list the word(s) with the highest frequency in a sentence across all sentences in the whole file, also print its frequency and the corresponding sentence. cannot use hash maps. assume text file will be multiple paragraphs long.
Use data from the table below to calculate the equilibrium constants at 25 ∘C for each...
Use data from the table below to calculate the equilibrium constants at 25 ∘C for each reaction. Standard Thermodynamic Quantities for Selected Substances at 25∘C Substance ΔH∘f(kJ/mol) ΔG∘f(kJ/mol) S∘(J/mol⋅K) H2(g) 0 0 130.7 N2(g) 0 0 191.6 Br2(g) 30.9 3.1 245.5 Cl2(g) 0 0 223.1 NO2(g) 33.2 51.3 240.1 N2O4(g) 9.16 99.8 304.4 NH3(g) -45.9 -16.4 192.8 P4(g) 58.9 24.4 280.0 PH3(g) 5.4 13.5 210.2 Part A 2NO2(g)⇌N2O4(g) Find K Part B Br2(g)+Cl2(g)⇌2BrCl(g) ΔG∘f for BrCl(g) is -1.0 kJ/mol Find...
Use data from Appendix IIB in the textbook to calculate the equilibrium constants at 25?C for...
Use data from Appendix IIB in the textbook to calculate the equilibrium constants at 25?C for each of the following reactions. 2NO(g)+O2(g)?2NO2(g) . Express your answer using two significant figures.
Use ?G?f values from Appendix IIB to calculate the equilibrium constants at 25 ?C for each...
Use ?G?f values from Appendix IIB to calculate the equilibrium constants at 25 ?C for each of the following reactions. a. 2NO2(g)?N2O4(g) b. 3/2H2(g)+1/4P4(g)?PH3(g)
Be able to identify the ASA Code of Ethics principles.
Be able to identify the ASA Code of Ethics principles.
Using the aqueous equilibrium constants, calculate the concentration of OH- in M and pH for the...
Using the aqueous equilibrium constants, calculate the concentration of OH- in M and pH for the following solutions (given that all are at 25 degrees celsius): 0.15 M NaBrO 8.2×10−2 M NaHS. A mixture that is 0.13 M in NaNO2 and 0.25 M in Ca(NO2)2. Thank you! :)
Click the block of code below and hit the Run button above. In [6]: from statsmodels.formula.api...
Click the block of code below and hit the Run button above. In [6]: from statsmodels.formula.api import ols # create the multiple regression model with mpg as the response variable; weight and horsepower as predictor variables. model = ols('mpg ~ wt+hp', data=cars_df).fit() print(model.summary()) OLS Regression Results ============================================================================== Dep. Variable: mpg R-squared: 0.825 Model: OLS Adj. R-squared: 0.813 Method: Least Squares F-statistic: 63.86 Date: Thu, 13 Feb 2020 Prob (F-statistic): 5.81e-11 Time: 23:12:29 Log-Likelihood: -70.042 No. Observations: 30 AIC: 146.1 Df...
Use BASH to make a code that takes any list of numbers and calculate the Median...
Use BASH to make a code that takes any list of numbers and calculate the Median and Mode.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT