1. Write a complete C++ program named “CheckAmount” that accepts command line arguments. It checks whether there is a command line argument of “-amount” followed by an amount number. It will print out that number amount. For all other cases, it will print out -1. For example, if you run this program with correct arguments as follows, it will print out 1.99, 0.75 and 1.1 respectively CheckAmount -amount 1.99 CheckAmount -help -amount 0.75 CheckAmount -help -check -amount 1.1 -verbose And if you run the program with invalid arguments, it will print -1 in all cases CheckAmount -amount -verbose CheckAmount -help -amount CheckAmount -amount CheckAmount amount 1.0 CheckAmount
Here is the c++ code:
#include <iostream>
#include <ctype.h> //for ifdigit() function
using namespace std;
//function to check if a string is floating point number or not
//it should have 0 or 1 dots and rest all digits
bool check(string s2)
{
int dots = 0;
for (int i = 0; i < s2.size(); ++i)
if (s2[i] == '.')
dots++;
else if (!isdigit(s2[i]))
return false;
else
continue;
if (dots < 2)
return true;
return false;
}
int main(int argc, char **argv)
{
for (int i = 1; i < argc; ++i)
string s(argv[i]);
if (s == "-amount")//if a command line argument is -amount
for (int j = i + 1; j < argc; ++j)//check the following arguments for a float number
string s2 = argv[j];
if (check(s2))
cout << s2 << endl;
return 0;
break;
cout << "-1" << endl;
return 0;
}
Sample IO:
![1: bash x TERMINAL [unseen@pc]07:16 am_$ ~/prog/CPP g++ CheckAmount.cpp -o CheckAmount [unseen@pc]07:17 am_$ ~/prog/CPP ./Che](http://img.homeworklib.com/images/4a3172c6-da3a-405d-9325-23322affe591.png?x-oss-process=image/resize,w_560)
1. Write a complete C++ program named “CheckAmount” that accepts command line arguments. It checks whether...
Make sure it is able to print everything and uses the
command line
Write a complete C++ program named “CheckAmount" that accepts command line arguments. It checks whether there is a command line argument of"-amount" followed by an amount number. It will print out that number amount. For all other cases, it will print out -1. For example, if you run this program with correct arguments as follows, it will print out 1.99, 0.75 and 1.1 respectively CheckAmount -amount 1.99...
Command line input In C++ it is possible to accept command line arguments. Command-line arguments are given after the name of a program in command-line operating systems like Linux and are passed in to the program from the operating system. To use command line arguments in the program, it must first understand the full declaration of the main function, which until now has accepted no arguments. In fact, main can accept two arguments: one argument is number of command line...
Write a C program, named sortit, that reads three integers from the command line argument and returns the sorted list of the integers on the standard output screen, For instance, >sortit 3 5 7 >The sorted list is 3, 5, 7. >sortit 4 0 9 >The sorted list is 0, 4, 9 >sortit 1 p 9 >sortit: invalid input p. >sortit >usage: sortit num1 num2 num3! 1. The source code of a c file 2. Screenshots that show successful execution...
Write a C Program that uses Command Line Arguments to convert the input string at the Command Line into Upper-Case, by traversing the argument at Command Line with the help of pointers.
Write a program in C that accepts a port number as a command line argument, and starts an HTTP server. This server should constantly accept() connections, read requests of the form GET /path HTTP/1.1\r\n\r\n read the file indicated by /path, and send it over the "connect" file descriptor returned by the call to accept().
Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text file by removing all blank lines (including lines that only contain white spaces), all spaces/tabs before the beginning of the line, and all spaces/tabs at the end of the line. The file must be saved under a different name with all the lines numbered and a single blank line added at the end of the file. For example, if the input file is given...
Write a full program that will accept any number of command line arguments and print them to the screen. Suppose your program is called Print.java. When the command java Print hello goodbye you is run, the output will be hello goodbye you Write a full program that will accept exactly three command line arguments that can be interpreted as integers, and will add them up. If there aren't exactly 3 command line arguments, print an error message and terminate the program....
Problem: Write a program that behaves as described below.If the first command-line argument after the program name (argv[1]) is “--help”, print the usage information for the program. If that argument is not “--help”, you are to expectargv[1]and subsequent arguments to be real numbers(C, integer, float, or double types)in formats acceptable to the sscanf()function of the C library or strings of ASCII chars that are not readable as real numbers. You are to read the numbers, count them and calculate the...
Your task is to write a C++ program that consumes integer values as command line arguments and returns the arithmetic mean of these values. To increase the flexibility of the program, there should be no set number of arguments. To overcome this, we will require the argument argv[1] to be the number of integers the user enters. For example, if the user wants to calculate the arithmetic mean of 4 numbers, they would pass in 4 as the first argument...
In C, Write a program that can accept an arbitrary number of command line arguments, e.g. program must do the following: program needs to split each of the arguments into two halves based on the length of a string. Specifically, the first half will be [0, n/2) and the second half will be [n/2] where n is the length of the string and n > 1. For instances, hello is split into two halves: he and llo. Similarly, world! is...