1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
AysviL [449]
4 years ago
11

Write a C++ program that takes two numbers from the command line and perform and arithmetic operations with them. Additionally y

our program must be able to take three command line arguments where if the last argument is 'a' an addition is performed, and if 's' then subtraction is performed with the first two arguments. Do not use 'cin' or gets() type functions. Do not for user input. All input must be specified on the command line separated by blank spaces (i.e. use the argv and argc input parameters).

Computers and Technology
1 answer:
Igoryamba4 years ago
8 0

Answer:

Here is code in C++.

// include header

#include <bits/stdc++.h>

using namespace std;

//main function with command line argument as parameter

int main(int argc, char *argv[])

{

   //extract all the arguments

   int frstNumb = atoi(argv[1]);

   int scndNumb = atoi(argv[2]);

   string argv3 = argv[3];

   //print all command line arguments

   

cout<<"first command line argument is: "<<argv[1]<<endl;

cout<<"second command line argument is: "<<argv[2]<<endl;

cout<<"third command line argument is: "<<argv[3]<<endl;

// if third argument is 'a' then addition of first two argument

if(argv3=="a")

{

int sum=frstNumb+scndNumb;

    cout<<"addition of two number is:"<<sum<<endl;

}

 //// if third argument is 's' then subtraction of first two argument

   else if(argv3=="s")

{

int diff=frstNumb-scndNumb;

    cout<<"subtraction of two number is:"<<diff<<endl;

}

 //invalid input

else

cout<<"invalid command line argument:"<<endl;

return 0;

}

Explanation:

Pass three command line arguments in the main function. Extracts all the argument. If the third argument is "a" then it will perform addition of first two arguments.If the third argument is "s" then it will perform subtraction of first two arguments.

Output:

first command line argument is: 3                                                                                                                              

second command line argument is: 4                                                                                                                            

third command line argument is: a                                                                                                                              

addition of two number is:7  

You might be interested in
Will give Brainliest 100 points answer only if you know
katrin [286]
There are five basic programming elements, or operations: input, output, arithmetic, conditional, and looping. Every program uses at least two of these.

The description of a programming language is usually split into the two components of syntax (form) and semantics (meaning).

Input: getting data and commands into the computer

Output:getting your results out of the computer

Arithmetic: performing mathematical calculations on your data

Conditional: testing to see if the condition is true or false

Looping: cycling through a set of instructions until some condition is met
7 0
3 years ago
Read 2 more answers
Which of the following things would you access from the Program &amp; Courses page? Course descriptions Tutorial videos Account
Paraphin [41]

Course descriptions.

5 0
3 years ago
Why is the human immunodeficiency virus so deadly?
damaskus [11]

<em> </em><em>I</em><em> </em><em>think</em><em> </em><em>the</em><em> </em><em>answer</em><em> </em><em>is</em><em> </em><em>D</em><em>.</em>

<em>It</em><em> </em><em>kills</em><em> </em><em>the</em><em> </em><em>cells</em><em> </em><em>that</em><em> </em><em>make</em><em> </em><em>antibodies</em><em>.</em>

<em>Hope</em><em> </em><em>this</em><em> </em><em>will</em><em> </em><em>help</em><em> </em><em>u</em><em>.</em><em>.</em>

8 0
3 years ago
Clunker Motors Inc. is recalling all vehicles in its Extravagant line from model years 1999-2002 as well all vehicles in its Guz
Aleksandr [31]

Answer:

The following code is written in java programming language:

//set if statement

if (((modelYear >= 1999) && (modelYear <= 2002) && (modelName == "Extravagant")) || ((modelYear >= 2004) && (modelYear <= 2007) && (modelName == "Guzzler")))

{

recalled = true;    //initialized Boolean value

}

else      //set else statement

{

recalled = false; ////initialized Boolean value

}

Explanation:

Here, we set the if statement and set condition, if the value of modelYear is greater than equal to 1999 and less that equal to 2002 and modelName is equal to "Extravagant" or the value of modelYear is greater than equal to 2004 and less than equal to 2007 and the model year is equal to "Guzzler", than "recalled" initialized to "true".

Otherwise "recalled" initialized to "true".

5 0
3 years ago
Help me with this two questions please
AnnyKZ [126]

Answer:

1 is def... don't know about the other one though sorry

6 0
2 years ago
Other questions:
  • Jessica has pinned her favorite applications as icons on her desktop. She always clicks on these icons to work on them. Which us
    10·1 answer
  • Processing is handled by the computer’s central processing unit (cpu).​ <br> a. True <br> b. False
    6·1 answer
  • Jenna wants to convert a decimal number to its octal form. Which option will she use to calculate the octal number?
    8·1 answer
  • Why are fixed resistors’ values indicated by color bands rather than printing the numeric value on their exterior?
    13·1 answer
  • Write the definition of a method, oddsMatchEvens, whose two parameters are arrays of integers of equal size. The size of each ar
    10·1 answer
  • An audit trail is a record of how a transaction was handled from input through processing and output
    10·1 answer
  • It is an electronic device that capable of accessing accepting processing product and storing data​
    13·1 answer
  • HELPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP!!!
    12·1 answer
  • Anyone use zoom<br><br>code:- 2574030731<br>pass:- HELLO<br>Z●●M ​
    14·2 answers
  • I'll mark you the brainlest please help
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!