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

Program needs to be written in C. Please type up answer to avoid in correct pict

ID: 3828971 • Letter: P

Question

Program needs to be written in C. Please type up answer to avoid in correct picture order or sloppy hand writing.

Introduction

The purpose of this assignment is to learn how to control the location of outputs written to the terminal window.

Main description

Make a function that will output a letter of the English alphabet in size 12 char by 16 char. For instance, if the letter is ‘H’ then the corresponding function will output the following 12x16 pattern.

H                          H

H                          H
H                          H
H                          H
H                          H
H                          H
H                          H
HHHHHHHHHHHH
H                          H
H                          H
H                          H
H                          H
H                          H
H                          H
H                          H
H                          H

Notice that the H is written in a 12x16 grid where each element of the grid is one ascii character. The upper left corner of this grid has a coordinate pair (x,y) to identify its location. Let’s suppose the name of the function is: show_H. Then its prototype will be

void show_H(int x, int y);             or          void show_H(int, int);

The x and y values received by the function tell the function where to draw the 12x16 character.

Use letters from your own name

Starting with your own family name (last name) pick 8 distinct characters for which you will make functions For example, the professor’s last name is “Holliday”. That means I will make functions as follows:

            Display_H

            Display_o

            Display_l

            Display_i

            Display_d

            Display_a

            Display_y

But that is only 7 characters. Therefore, the professor has to go to his first name and select one more character to make the function below.

            Display_F

You have to find 8 different characters in your name so that you can have 8 different functions.

Make a complete program

You need a main program that will call your letter functions. You create a main program that behaves according to the sample run below.

Sample run

Welcome to Ascii Letters.

These are the available letters: F H a d i l o y

Enter a letter to display (cntl+D to quit): d

Enter the coordinates: 5 2

Enter a letter to display (cntl+D to quit); y

Enter the coordinates: 28 6

Enter a letter to display (cntl+D to quit): ^D

Thank you for your inputs. Your letters are here:

               d

               d

               d

               d            y              y

               d            y            y

               d              y          y

               d               y        y

               d                y      y

            dddd                 y    y

         dddd d                  y y

       ddd     d                   yy

       dd      d                   yy

       dd      d                   yy

       ddd     d                   yy

        dddd   d                   yy

          dddddd                   yy

                                   yy

                                   yy

Thank you for using this ascii art program.

Please come back again.

Notice that the ‘y’ character is slightly lower than the ‘d’ character. This is because the user entered a vertical coordinate for ‘y’ that is bigger than the vertical coordinate of ‘d’.

Program architecture

There will be one main file and 8 characters files. Each character file contains one function, and that function will display exactly one character.

Test data

Again in this assignment you do not have to check for bad inputs. We are assuming the user only enters valid data. We assume that the characters entered by the user are from the displayed list. We also assume that the coordinate values are in the valid range. For example, a negative coordinate number is invalid in this assignment.

Explanation / Answer

#include <stdio.h>

void Display_H(int x, int y);
void Display_I(int x, int y);
void Display_L(int x, int y);
void Display_T(int x, int y);
int main()
{
   char letter;
   int x,y;
    printf("Welcome to Ascii Letters. ");
   printf("These are the available letters: I H T L ");
   printf("Enter a letter to display: ");
   scanf("%c",&letter);
   printf("Enter the coordinates ");
   scanf("%i %i",&x,&y);
  
   switch (letter)
     {
        case 'I':
           Display_I(x,y);
           break;
        case 'T':
           Display_T(x,y);
           break;
        case 'L':
           Display_L(x,y);
           break;
        case 'H':
           Display_H(x,y);
           break;
        default:
           printf("Please choose any Letter and coordinates to continue... ");
     }
  

    return 0;
}

void Display_I(int x, int y){
  
    int m=x/2;
  
    for(int i=0;i<y;i++){
       for(int j=0;j<x;j++){
            if(i==0){
                for(int n=0;n<x;n++){
                   printf("I");
               }
               printf(" ");
               break;
           }
           else if(j == m){
                //printf("j = m ");
               printf("I");
               printf(" ");
               break;
           }
           else if(i == y-1){
               for(int n=0;n<x;n++){
                   printf("I");
               }
               printf(" ");
               break;
           }
          
           else{
               printf(" ");
           }
          
       }
    }
}

void Display_H(int x, int y){
   int m=y/2;
  
    for(int i=0;i<y;i++){
       if(i==m){
           for(int j=0;j<x;j++){
               printf("H");
           }
           printf(" ");
          
       }
       for(int j=0;j<x;j++){
           if(j==0){
               printf("H");
           }
           else if(j==x-1){
                printf("H ");
                break;
           }
           else{
               printf(" ");
           }
          
       }
    }
}

void Display_L(int x,int y){
   for(int i=0;i<y;i++){
       if(i==y-1){
           for(int j=0;j<x;j++){
               printf("L");
           }
       }
       else{
           printf("L ");
        }
    }
}

void Display_T(int x,int y){
   int m=x/2;
  
    for(int i=0;i<y;i++){
       for(int j=0;j<x;j++){
            if(i==0){
                for(int n=0;n<x;n++){
                   printf("T");
               }
               printf(" ");
               break;
           }
           else if(j == m){
                //printf("j = m ");
               printf("T");
               printf(" ");
               break;
           }
           else{
               printf(" ");
           }
       }
    }
}