Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Using this starter code: 

#include <stdio.h>

//function prototypes
void PrintLine(int length, char theChar);
void PrintRectangle(int width, int height, char theChar);
void PrintTriangle(int baseLength, char theChar);
void PrintInvertedTriangle(int height, char theChar);

int main(void)

{

    char choice;
    int a, b;   
    char character;   

    //asking for user input
    printf("Which shape (L-line, T-triangle, R-rectangle, I-inverted triangle): \n");
    scanf(" %c", &choice);
    printf("Which character: \n");
    scanf(" %c", &character);
    switch (choice)
{
  
    //if user input is for a triangle
    case 'T':
    case 't':
    printf("Enter an integer base length between 3 and 25: \n");
    scanf("%d", &a);
    if (a >= 3 && a <= 25)   
    PrintTriangle(a, character);
    else
    printf("Length not in range.");
    break;

    //if user input is for a rectangle
    case 'R':
    case 'r':
    printf("Enter an integer width and height between 2 and 25: \n");
    scanf("%d%d",&a, &b);
    if((a<2 || a>25 )){
        printf("Width not in range.");
        break;
        }
  
    if((b<2||b>25)){
        printf("Height not in range.");
        break;
        }
        if(a >= 2&&a<=25 && b>=2&&b<=25)
        PrintRectangle(a, b, character);
        break;

    //if user input is a line
    case 'L':
    case 'l':
    printf("Enter an integer length between 1 and 25: \n");
    scanf("%d", &a);
    if (a >= 1 && a <= 25)   
    PrintLine(a, character);
    else
    printf("Length not in range.");
    break;

    //if user input is an inverted triangle
    case 'i':
    case 'I':
    printf("Enter an integer base length between 2 and 25: \n");
    scanf("%d", &a);
    if (a >= 2 && a <= 25)   
    PrintInvertedTriangle(a, character);
    else
    printf("Height not in range.");
    break;

    //if user input isn't a line, rectagnle, triangle or inverted triangle
    default:
    printf("Unknown shape.\n");
    break;
    }
    }

    //line function
    void PrintLine(int length, char theChar)
    {
        int i;
        for (i = 0; i < length; i++)
        printf("%c", theChar);
        printf("\n");
    }

    //triangle function
    void PrintTriangle(int baseLength, char theChar)
    {
        int i, j;
        for (i = 1; i <= baseLength; i++)
        {
            for (j = 0; j < i; j++)
            printf("%c", theChar);
            printf("\n");
        }
    }

    //rectangle function
    void PrintRectangle(int width, int height, char theChar)
    {
        int i, j;
        for (i = 0; i < height; i++)
        {
            for (j = 0; j < width; j++)
            printf("%c", theChar);
            printf("\n");
            }
        }

    //inverted triangle function
    void PrintInvertedTriangle(int height, char theChar)
    {
        int i;
        for (i = height; i > 0; i--)
        {
            PrintLine(i, theChar);
  
        }
    }

Answer this prompt in C programming: 

 

Using your solution to CE_6.2 as your starter code:
Create a new void function to print a pyramid called PrintPyramid.
• Modify your prompt for the new shape:
o p or P for a pyramid
• then prompt for a width (range 2 - 25)
. if the width is valid, call the PrintPyramid function
You must implement your PrintPyramid function using ONLY the user defined functions you have
written so far. There should be NO LOOPS in the function implementation!
NOTES:
You must verify the input range.
• All previous functions must work properly, and all previous (CE_6.1 and CE_6.2) test cases must still pass.
Sample output (sample input shown with underline):
Which shape (L-line, T-triangle, R-rectangle, I-inverted triangle, P-pyramid): P
Which character: $
Enter an integer width between 2 and 25: 26
Width not valid.
Which shape (L-line, T-triangle, R-rectangle, I-inverted triangle, P-pyramid):
Which character: ^
Enter an integer width between 2 and 25: 6
AAA
AAAA
AAAAA
AAAAA A
AAAAA
AAAA
AAA
expand button
Transcribed Image Text:Using your solution to CE_6.2 as your starter code: Create a new void function to print a pyramid called PrintPyramid. • Modify your prompt for the new shape: o p or P for a pyramid • then prompt for a width (range 2 - 25) . if the width is valid, call the PrintPyramid function You must implement your PrintPyramid function using ONLY the user defined functions you have written so far. There should be NO LOOPS in the function implementation! NOTES: You must verify the input range. • All previous functions must work properly, and all previous (CE_6.1 and CE_6.2) test cases must still pass. Sample output (sample input shown with underline): Which shape (L-line, T-triangle, R-rectangle, I-inverted triangle, P-pyramid): P Which character: $ Enter an integer width between 2 and 25: 26 Width not valid. Which shape (L-line, T-triangle, R-rectangle, I-inverted triangle, P-pyramid): Which character: ^ Enter an integer width between 2 and 25: 6 AAA AAAA AAAAA AAAAA A AAAAA AAAA AAA
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education