Question

Example 1 of command and output Example 3 of command and output You will create a C++ program that can read the arguments, ac

C++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include<stdlib.h>
using namespace std;
  
int main(int argc, char** argv)
{
   int num1=atoi(argv[1]);
   int num2=atoi(argv[2]);
   if ((argc==3)&&(0<num1)&&(num1<10)&&(0<num2)&& (num2<10))//validates the number of arguments and range of input
{

   int i,j,k,l;
   for(i=1;i<11 && (j+num1)<12;i=i+num2)//j+num1<12 checks whether whole # can seat in the row
   {
   for(j=1;j<i;j++)//print first *
   cout<<"*";
   for(k=j;k<(j+num1) ;k++)//print #
   cout<<"#";
   for(l=k;l<12;l++)//print second *
   cout<<"*";
   cout<<"\n";
}
}
else
cout<<"Please Enter correct number of integer arguments";

return 0;
}

RESULT:

main 1 2
#**********
**#********
****#******
******#****
********#**

Add a comment
Know the answer?
Add Answer to:
C++ Example 1 of command and output Example 3 of command and output You will create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Objective: Use input/output files, strings, and command line arguments. Write a program that processes a text...

    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...

  • Your task is to write a C++ program that consumes integer values as command line arguments...

    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...

  • Write a program that finds either the largest or smallest of the ten numbers as command-line...

    Write a program that finds either the largest or smallest of the ten numbers as command-line arguments. With –l for largest and –s for smallest number, if the user enters an invalid option, the program should display an error message. Example runs of the program: ./find_largest_smallest –l 5 2 92 424 53 42 8 12 23 41 output: The largest number is 424    ./find_largest_smallest –s 5 2 92 424 53 42 8 12 23 41 output: The smallest number is...

  • I/O program for C Write a program in direct1.c which reads from standard input a line...

    I/O program for C Write a program in direct1.c which reads from standard input a line and then outputs that line immediately to standard output. it should read the first line only ! Then, write another program called direct2.c which reads from standard input every line until end of input and outputs them to standard output. Everything that goes in should come out exactly as it was. Compile both programs and run them on the input files given below The...

  • 1) Write a complete C or C++ program to print Hello World Greetings. 2) Using the...

    1) Write a complete C or C++ program to print Hello World Greetings. 2) Using the command line, compile and generate the executable for the above program. Let’s call helloWorld the target executable. 3) Write a C program that does the following: a) forks a child to execute helloWorld b) waits for the child execution to end 4) Reuse the above program to try a different variant of exec family of system calls. OPTIONAL: 1) write a program main that...

  • LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command...

    LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command line arguments and does NOT use the read command. I will give you no credit if your bash script includes a read command. Also, you need to have at least one for..in loop in your code even if there may be other ways to do this problem. The script will go through a list of entries in the current directory (do not process subdirectories):...

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

  • Write a program that finds either the largest or smallest of the ten numbersas command-line arguments....

    Write a program that finds either the largest or smallest of the ten numbersas command-line arguments. With –l for largest and –s for smallest number, if the userenters an invalid option, the program should display an error message.Example runs of the program: ./find_largest_smallest –l 5 2 92 424 53 42 8 12 23 41output: The largest number is 424 ./find_largest_smallest –s 5 2 92 424 53 42 8 12 23 41output: The smallest number is 2 1) Name your program...

  • Problem: Write a program that behaves as described below.If the first command-line argument after 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...

  • Write a C++ program that takes two numbers from the command line and perform and arithmetic...

    Write a C++ program that takes two numbers from the command line and perform and arithmetic operations with them. Additionally your 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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT