Question

// HW Lab 22 // Demonstrates passing arguments to function parameters. // Basically, the function from...

// HW Lab 22
// Demonstrates passing arguments to function parameters.
// Basically, the function from HW Lab 21 will be made
// more flexible. Pass in the number of characters
// to print on the line and which character (symbol)
// the line should be made up of.

\*
The following constants are available in C++ and must be used:
char: CHAR_MIN, CHAR_MAX
short: SHRT_MIN, SHRT_MAX
int: INT_MIN, INT_MAX
long: LONG_MIN, LONG_MAX
*/

#include <iostream>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;

// TODO: Write function prototype here. This function should be:
// Name: PrintLine
// Parameter(s): howMany & symbolToPrint (use appropriate data types)
// Returns: <nothing>

//-----------------------------------------------------------------------------

int main()
{
   /* Create a program that produces the Sample Output shown at the bottom.

   You MUST:
   - Output all of the lines show below in the Sample Output - spacing, spelling,
punctuation, etc. must be exact matches
   - Declare variables and/or constants appropriately, name them according to standards
   (points will be deducted for poor names), and be sure to use appropriate data types.
   - NOTE: Call the function where appropriate - passing the values to create the line correctly
   - NOTE: You MUST use setw to put values into columns properly.
   The ONLY place you may (and should) use blank spaces is
   between the words in the two title lines and in the
   "Data type" column header.
   - NOTE: Not every line is the same length or uses the same character symbol.
   - NOTE: You may only declare and implement one function.

   */
   // <write your solution code below this comment>


   return 0;
}

//-----------------------------------------------------------------------------

// TODO: Write the PrintLine function definition here
// Be sure that the function heading matches the prototype above

// PrintLine()
// prints symbolToPrint repeatedly (as defined by howMany) on one line


//-----------------------------------------------------------------------------

/* Sample program output:

*********************************************
Simple C++ Integer Types
(Microsoft Specific)
----------------------------------------
Data type Range
----------------------------------------
char: -128 to 127
short: -32768 to 32767
int: -2147483648 to 2147483647
long: -2147483648 to 2147483647
*********************************************

*/

Homework Answers

Answer #1

NOTE:- IN THE EXPECTED OUTPUT THE RANGE OF LONG IS GIVEN WRONG , SO I HAVE PRINTED THE CORRECT RANGE USING LONG_MIN AND LONG_MAX

" * " are printed 45 times and " -" are printed 40 times in the sampe output therefore same numbers are used in main() aswell.

Code for the following question:-

#include <iostream>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;


void PrintLine(int howMany,char symbolToPrint);// function prototype

int main()
{
  
char star ='*',dash='-';
const int n1=45,n2=40;
PrintLine(n1,star);
cout<<"Simple C++ Integer Types\n(Microsoft Specific)\n";
PrintLine(n2,dash);
cout<<setw(10)<<"Data type"<<setw(23)<<"Range\n" ;
PrintLine(n2,dash);
cout<<setw(7)<<"char:"<<setw(20)<<CHAR_MIN<<" to " <<CHAR_MAX<<"\n";
cout<<setw(7)<<"short:"<<setw(20)<<SHRT_MIN<<" to " <<SHRT_MAX<<"\n";
cout<<setw(7)<<"int:"<<setw(20)<<INT_MIN<<" to " <<INT_MAX<<"\n";
cout<<setw(7)<<"long:"<<setw(20)<<LONG_MIN<<" to " <<LONG_MAX<<"\n";
PrintLine(n1,star);


return 0;
}

void PrintLine(int howMany,char symbolToPrint) // function definition
{
for(int i=0;i<howMany;i++)
{
cout<<symbolToPrint;
}
cout<<endl;
}

Screenshot of IDE:-

Screenshot of output:-

**************** Feel free to leave a comment in case of any doubt . If this answer helped you , don't forget to hit upvote ********************

Know the answer?
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
Similar Questions
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
// Lab Homework 9 // Logical Operator AND and OR // Demonstrate how to use a...
// Lab Homework 9 // Logical Operator AND and OR // Demonstrate how to use a logical operator // with a Boolean expression. #include <iostream> #include <cctype> // for tolower() using namespace std; int main() {    /* Create a program that produces the Sample Output shown at the bottom.    You MUST:    - Output all of the lines show below in the Sample Output - spacing, spelling, punctuation, etc. must be exact matches    NOTE: There are FOUR...
/* Homework Lab 4 - Using manipulators to format output */ //***************************************************************** // Mortgage Payment Calculator...
/* Homework Lab 4 - Using manipulators to format output */ //***************************************************************** // Mortgage Payment Calculator program // This program determines the monthly payments on a mortgage given // the loan amount, the yearly interest, and the number of years. //***************************************************************** #include <iostream> // Access cout #include <cmath> // Access power function #include <iomanip> // Access manipulators using namespace std; const float LOAN_AMOUNT = 50000.00; // Amount of the loan const float YEARLY_INTEREST = 0.0524; // Yearly interest rate const...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour notation. For example, it should convert 14:25 to 2:25 PM. (A) The user provides input as two integers separated by ‘:’. The following function prototype should capture the user inputs as described below: void input(int& hours24, int& minutes); //Precondition: input(hours, minutes) is called with //arguments capable of being assigned values. //Postcondition: // user is prompted for time in 24 hour format: // HH:MM, where...
Please follow ALL the instructions and solve it by C++. Please and thank you! There are...
Please follow ALL the instructions and solve it by C++. Please and thank you! There are two ways to write loops: (1) iterative, like the for-loops we're used to using, and (2) recursive. Your prerequisite preparation for this course should have exposed you to both, although your working knowledge of recursive loops may not be as strong as that of iterative loops. Consider the following iterative function that prints an array of characters backward: #include <iostream> #include <cstring> // print...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
Implement and demonstrate a disk-based buffer pool class based on the LRU buffer pool replacement strategy....
Implement and demonstrate a disk-based buffer pool class based on the LRU buffer pool replacement strategy. Disk blocks are numbered consecutively from the beginning of the file with the first block numbered as 0. Assume that blocks are 4096 bytes in size. Use the supplied C++ files to implement your LRU Buffer Pool based on the instructions below. • Implement a BufferBlock class using the supplied BufferBlockADT.h o Your Buffer Block must inherit BufferBlockADT or you will not get credit...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
In Java please 10.9 Lab 6 In BlueJ, create a project called Lab6 Create a class...
In Java please 10.9 Lab 6 In BlueJ, create a project called Lab6 Create a class called LineSegment –Note: test changes as you go Copy the code for LineSegment given below into the class. Take a few minutes to understand what the class does. Besides the mutators and accessors, it has a method called print, that prints the end points of the line segment in the form: (x, y) to (x, y) You will have to write two methods in...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT