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
Wendy had been searching the internet for a great deal on jewelry. While looking at one site, a pop-up was displayed that told h
tigry1 [53]

Answer:

boot the computer from the windows installation disk and run startup repair

Explanation:

Based on the scenario being described within the question it can be said that the best option in this situation would be to boot the computer from the windows installation disk and run startup repair. This will analyze all windows files and clean up any files or malicious software that does not belong in order for the system to be able to correctly boot into the operating system. Then from inside the operating system you can run a full diagnostic of the system.

4 0
3 years ago
The space where text and content is entered and positioned for onscreen reading or printing
tino4ka555 [31]

Answer:

Page.

Explanation:

A page typically occupies the largest portion of a document layout as it houses the main writeup or content of the document. The text contained in a document is written on a the main page of the document. The main page is surrounded by the page margin, which is an area which separates the tips or edges of an entire papwr and the writing area (page) of the document. The insertion point refers to an indicator which shows the position which a typed character will fall or be placed. Content written on a document's page is what is printed when the document is to be printed out and test entered on the page are what is seen by the reader.

4 0
3 years ago
Borrowers taking a balloon payment mortgage most likely plan to rent out their homes. must repay the loan in five to ten years.
lesantik [10]
Borrowers taking a balloon payment mortgage most likely "<span>must repay the loan in five to ten years".
</span>

<span>B<span>alloon payment refers to a fixed amount of money connected to a loan someone takes; this sum has a greater value than the actual repayment costs and can be applied at fixed periods of time at the end. </span>It can run for longer periods as well.</span>

5 0
4 years ago
Read 2 more answers
What were the names of Henry VIII's six wives?
timurjin [86]

Answer:

Jane Seymour,Anne Boleyn,Katherine of Aragon,Anne of Cleves,Katherine Howard,Katherine Parr

Explanation:

7 0
2 years ago
Read 2 more answers
Which of the following is not a group of energy sources?
Dimas [21]

Answer:

nonrenewable

Explanation:

Brainliest please

4 0
3 years ago
Read 2 more answers
Other questions:
  • A honeypot is sometimes called a(n) __________.
    11·1 answer
  • (count single digits) * write a program that generates 100 random integers between 0 and 9 * and displays the count for each num
    7·1 answer
  • Hardware consists of the physical devices associated with a computer system, where software is the set of instructions the hardw
    13·1 answer
  • Which is an internet service? <br> A.) antivirus <br> B.) chat <br> C.) firewall<br> D.) router
    6·2 answers
  • Write a Python program that asks the user for a positive, odd value. Once the value is validated determine if the number is Prim
    11·1 answer
  • How would asking questions or defining problems be used in this career?<br> -
    13·1 answer
  • Rebecca is an interior designer. What is her job role? need this asap
    9·1 answer
  • What role do computer play in law and order​
    6·1 answer
  • Which of the following networks had these two goals: a) allowing scientists to work together on scientific projects; and, b) fun
    8·2 answers
  • What is tha length of Mac address ?​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!