Question: By making changings in the following source code (written in C++) and remove multi character error, get a output of name ASAD in *
By making changings in the following source code (written in C++) and remove multi character error, get a output of name "ASAD" in " * " asterisk pattern. Also use the same loops
SOURCE CODE:
#include using namespace std;
int height = 5;
int width = (2 * height) - 1;
int abs(int d)
{ return d < 0 ? -1 * d : d; }
void printA() { int n = width / 2, i, j; for (i = 0; i < height; i++) { for (j = 0; j <= width; j++) { if (j == n || j == (width - n) || (i == height / 2 && j > n && j < (width - n))) cout <<"*"; else cout <<" "; } cout <<" "; n--; } } void printS() { int i, j; for (i = 0; i < height; i++) { for (j = 0; j < height; j++) { if ((i == 0 || i == height / 2 || i == height - 1)) cout <<"*"; else if (i < height / 2 && j == 0) cout <<"*"; else if (i > height / 2 && j == height - 1) cout <<"*"; else cout <<" "; } cout <<" "; } }
void printD() { int i, j; for (i = 0; i < height; i++) { cout <<"*"; for (j = 0; j < height; j++) { if ((i == 0 || i == height - 1) && j < height - 1) cout <<"*"; else if (j == height - 1 && i != 0 && i != height - 1) cout <<"*"; else cout <<" "; } cout <<" "; } } void printPattern(char character) { switch (character) case 'A': printA(); switch (character) case 'S': printS(); switch (character) case 'D': printD();
} int main() { char STRING = 'S'; printPattern(STRING);
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
