Get a copy of the functionP.cpp.
The purpose of this program is to practice using user defined functions.
——————————————————————————————————————————————————————
// Program functionP prints a triangle of the stars. // For example: // ***** // **** // *** // ** // * #include <iostream> #include <iomanip> using namespace std; /* FILL IN the function prototype for PrintStars */ int main () { int numofstars; cout << "Enter the number of stars in the first line: " << endl; cin >> numofstars; while (numofstars > 0) { /* FILL IN code to invoke function PrintStars */ /* Update the control variable numofstars */ } return 0; } //**************************************************************************** void PrintStars(int NUM) { /* FILL IN Code to print the number of NUM stars in a line by using a loop*/ }
—————————————————————————————————————————————————————————-
Add code to the program to complete it.
Compile and run this C++ program.
Expert Answer
#include <iomanip>
using namespace std;
/* FILL IN the function prototype for PrintStars */
void PrintStars(int);
int main ()
{
int numofstars;
cout << “Enter the number of stars in the first line: ” << endl;
cin >> numofstars;
while (numofstars > 0)
{
/* FILL IN code to invoke function PrintStars */
PrintStars(numofstars);
/* Update the control variable numofstars */
numofstars = numofstars -1;
}
return 0;
}
//****************************************************************************
void PrintStars(int NUM)
{
/* FILL IN Code to print the number of NUM stars in a line by using a loop*/
for(int count=0; count < NUM; count++) {
cout << “*”;
}
cout << endl;
}