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
Why might you use the More button in the Find and Replace dialog box?
den301095 [7]

Answer:

Use the More button to display more options to help narrow the search criteria.

Explanation:

<em> I think hope this helps you!!</em>

6 0
3 years ago
Which three pieces of information should be included in an artist statement? Select all that apply.
Dima020 [189]

Answer:

There is no answers given??

Explanation:

N/A

4 0
3 years ago
What three best practices can help defend against social engineering attacks?
lina2011 [118]

The three best practices that can help protect against social engineering are:

  • Be watchful of instructions to click on enticing web links.
  • Educate employees regarding policies.
  • Avoid disclosing your login details.
<h3>Social engineering</h3>

This refers to online crimes that are socially engineered or designed to trick victims into providing certain information or carrying out certain actions that would cause unknown harm to them or others.

For example, they may be tricked into revealing their security information or other personal information via email correspondence.

You can learn more about social engineering here brainly.com/question/26072214

#SPJ12

6 0
2 years ago
The Office ____ is a temporary storage area. Warehouse Clipboard Storehouse Gallery
yanalaym [24]
The answer is The Office Clipboard.

In most Microsoft Windows, Office Clipboard is used as a temporary storage for some software applications such as Microsoft Office Applications. It allows you to store up to 24 items either texts or graphics. For example, when you copy a text from one location this text will be temporarily stored in the clipboard until you paste them to another location.
4 0
3 years ago
Explain what the hazard detection unit is doing during the 5th cycle of execution. Which registers are being compared? List all
kondaur [170]

Answer:

<em>The registers that are compared are instructions 3 and 4</em>

<em>Explanation:</em>

<em>From the question given,</em>

<em>Recall that we need to explain what the hazard detection unit is doing  during the 5th cycle of execution and which registers are being compared.</em>

<em>Now,</em>

<em>The instructions on the 5th cycle, at the stage ID/EX and IF/ID:</em>

<em>The instruction values are in ID/EX : sub $t2, $t3, $t6 (instruction 3)</em>

<em>The instruction values are in IF/ID: sub $t3, $t1 $t5 (instruction 4)</em>

<em>The register $t3 is compared in the instructions 3 and 4</em>

<em>The hazard detection unit between instruction 4 and 5t o be compared, it need to find out the values of $t1</em>

<em />

7 0
3 years ago
Other questions:
  • How many people watch Anime in the world?
    15·2 answers
  • If you wish to sign out of your Microsoft account, tap or click ____ on the ribbon to open the Backstage view and then tap or cl
    8·1 answer
  • The purpose of a software design is to enable programmers to implement the requirements by designating the projected parts of th
    14·1 answer
  • a rule that states each foreign key value must match a primary key value in the other relation is called the
    5·1 answer
  • Which tool will select the lines of a sketch in digital software?
    7·1 answer
  • Three common risk factors for young drivers and how you plan to minimize these factors.
    13·1 answer
  • Explain the functions of a VDU?
    6·1 answer
  • A carver begins work on the following block of granite that weighs 2700 g. What is the density of the granite?
    13·1 answer
  • How do you write a multiplication formula in excel with an absolute refrence?
    11·1 answer
  • A large number of consecutive IP addresses are available starting at 198.16.0.0. Suppose that four organizations, Able, Baker, C
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!