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
The ____ method writes a newline character after the data.
Vera_Pavlovna [14]
The “Write” method writes a newline character, not “WriteLine”
6 0
3 years ago
An isp is a group of updates, patches, and fixes that apply to specific oss.
olasank [31]
<span>The statement that an ISP is a group of updates, patches, and fixes that apply to specific OSs is false.
</span> ISP stands for Internet service provider, while OSS stands for Operations support system.<span> The term ISP denotes a company or</span><span> organization that provides services for accessing, using, or participating in the Internet. OSS on the other hand is used by the providers to manage their networks.
</span>
4 0
3 years ago
What is the difference between Packaged and tailored soft ware?​
Rainbow [258]

Answer:

<em>Package software is developed by computer technicians. modified or changed if there is need because these software are custom-built. Tailored Software- Tailored software is the software that is developed as per the specifications and requirements of the users.</em>

Explanation:

hpithlps.

4 0
3 years ago
Mobile Device Managment includes all of the following except
Gemiola [76]

Answer: Physical damage protection

Explanation:

Mobile device management included all the above mention features except physical damage protection as, mobile management system do not responsible for any physical damage.

Mobile device management system are only responsible for protection of the various mobile devices, app security and also provide data transmission protection.

As, there is no policy in the mobile device management system which include any type protection from physical damage. It is only responsible for control data error in the devices and software protection.

7 0
3 years ago
Which of the following is needed if a computer with the IP address 172.31.210.10/24 wants to communicate with a computer with th
ozzi

Answer:

The answer is <em>since both ip addresses are not within the same subnet,   only router can be used for the two computers to communicate together.</em>

Explanation:

From the statements in the question, since  the two ip addresses are not on same subnet value i.e 172.31.210.10/24 and 172.31.209.122/24 then both computers cannot communicate except a router is used for network connections for the two different subnets as they are not on the same network.

Explanation:

4 0
3 years ago
Other questions:
  • Determine the value of base x of (211)x=(152)8
    8·2 answers
  • Which of the following is an Important criterion for evaluating the effctiveness of a graphic organizer
    14·2 answers
  • Which clauses in the Software Engineering Code of Ethics are upheld by a whistleblower (check all that apply). "Respect confiden
    15·1 answer
  • Step into my world
    7·2 answers
  • If we assume the modern view of existential import, why is the following syllogism invalid? No computer is made of clay. All com
    15·1 answer
  • Technology, by itself is neither good nor bad.<br> A) true<br> B) false
    11·2 answers
  • IF YOU LOVE GOD HELP ME......What should be covered in the conclusion of a presentation?
    11·2 answers
  • Identify the correct answer in each item. Write your answer on the blank provided before
    13·1 answer
  • This class is missing a number of functions. Rewrite the class declaration to follow best practices, e.g, operators, three impor
    10·1 answer
  • Older systems that often contain data of poor quality are called ________ systems.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!