// 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
*********************************************
*/
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 ********************
Get Answers For Free
Most questions answered within 1 hours.