This program must be in C++. Suppose you are building a program which draws seve
ID: 3691681 • Letter: T
Question
This program must be in C++.
Suppose you are building a program which draws several stars on the console. On the first three lines, there should be 1, 2, and 3 stars, respectively. On all subsequent lines, the number of stars should either be twice the number of stars 2/3 of the way up the screen, for lines numbers that are exact multiples of three, or otherwise 2 more than the preceding line. Write a recursive definition for the number of stars on each line.
Then, implement the recursive function from above, add a method to draw any number of stars (that can be iterative, i.e. using a loop, or it can be recursive), and call it enough times print stars on 54 lines.
The first few lines should look like this:
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
void printStar(int p,int s,int n){
if(s>=n)
return;
for(int i=1;i<=p+2;i++)
cout << "*" << flush;
cout << endl;
printStar(p+2,++s,n);
}
int main()
{
int n;
cout << "Enter the no:of lines :" << endl;
cin >> n;
cout << "*" << endl;
cout << "**" << endl;
cout << "***" << endl;
printStar(3,4,n);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.