Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

reate a project titled Lab5_Figures. This project shall contain multiple files.

ID: 3871521 • Letter: R

Question

reate a project titled Lab5_Figures. This project shall contain multiple files. Write a program that repeatedly asks the user to select either square, left or right triangle, then inputs the figure size and then prints the appropriate shape in stars. For square, the program should ask whether the user wants a filled or a hollow square. The program should quit if the user inputs an invalid option. See an example dialog below: 1. square 2. top left triangle 3. top right triangle select figure: 1 select size: 4 filled or hollow [f/h]: h **** * * * * **** 1. square 2. top left triangle 3. top right triangle ... You can reuse your code from the Looping lab. Place star-printing code in four separate functions: filledSquare, hollowSquare, leftTriangle and rightTriangle. Each function should accept a single integer parameter - the size of the figure and return no value (be a void-function). Create three separate files figures.cpp, figures.h, and figuresInput.cpp. Place the triangle and square function definitions in figures.cpp and their prototypes in figures.h. Make sure that the header file is protected against multiple inclusion. Place the main function in figuresInput.cpp

The code to be used is:

#include <iostream>

using std::cin; using std::cout; using std::endl;

int main() {

cout << "Input Number: ";

int n;

cin >> n;

for (int i = 0; i < n; i++)

{

for (int j = 0; j < n; j++)

cout << "*";

cout << endl;

}

cout << endl;

cout << endl;

for (int i = n; i > 0; i--)

{

for (int j = 1; j <= i; j++)

cout << "*";

cout << endl;

}

cout << endl;

for (int i = 0; i < n; i++)

{

for (int j = 0; j < i; j++)

cout << " ";

for (int j = 0; j < n - i; j++)

cout << "*";

cout << endl;

}

cout << endl;

cout << endl;

for (int i = 0; i < n; i++)

{

for (int j = 0; j < n; j++)

{

if (i == 0)

cout << "*";

else if (j == 0)

cout << "*";

else if (i == n-1)

cout << "*";

else if (j == n-1)

cout << "*";

else

cout << " ";

}

cout << endl;

}

}

Explanation / Answer

sbit PWM_Pin = P2^0;

void cct_init(void);

void InitTimer0(void);

void InitPWM(void);

unsigned char PWM = 0;   

unsigned int temp = 0;   

#define PWM_Freq_Num 257

int main(void)

{

cct_init();   

InitPWM();   

PWM = 127;   

while(1)   

{}

}

// Init CCT function

void cct_init(void)

{

P0 = 0x00;

P1 = 0x00;

P2 = 0x00;

P3 = 0x00;  

}

void InitTimer0(void)

{

TMOD &= 0xF0;   

TMOD |= 0x01;   

TH0 = 0x00;   

TL0 = 0x00;   

ET0 = 1;

EA = 1;

TR0 = 1;

// PWM initialize

void InitPWM(void)

{

PWM = 0;

InitTimer0();

}

// Timer0 ISR

void Timer0_ISR (void) interrupt 1

{

TR0 = 0; // Stop Timer 0

if(PWM_Pin) // if PWM_Pin is high

{

PWM_Pin = 0;

temp = (255-PWM)*PWM_Freq_Num;

TH0 = 0xFF - (temp>>8)&0xFF;

TL0 = 0xFF - temp&0xFF;

}

else // if PWM_Pin is low

{

PWM_Pin = 1;

temp = PWM*PWM_Freq_Num;

TH0 = 0xFF - (temp>>8)&0xFF;

TL0 = 0xFF - temp&0xFF;

}

TF0 = 0;

TR0 = 1;

}

void main()

{

int A[4][4],I,J;

clrscr();

printf("ENTER MATRIX A VALUES ");

for(I=0;I<4;I++)

{

for(J=0;J<4;J++)

{

scanf("%d",&A[I][J]);

}

}

printf("LOWER MATRIX C VALUES ARE : ");

for(I=0;I<4;I++)

{

printf(" ");

for(J=0;J<=I;J++)

{

printf("%d ",A[I][J]);

}

printf(" ");

}

printf("UPPER MATRIX C VALUES ARE : ");

for(I=0;I<4;I++)

{

printf(" ");

for(J=0;J<4;J++)

{

if(J>=I)

printf("%d ",A[I][J]);

else

printf(" ");

}

printf(" ");

}

printf(" ");

getch();

}

#include<stdio.h>

02

int main()

03

{

04

int value = 6;

05

for(int i = 1; i < value+1; i++);

06

{

07

for(int j = 1; j <= i; j++);

08

printf("*");

09

printf(" ");

10

}

11

return 0;

12

}