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

Untitled- Edited ST Insert Table Chart Text Shape Media Comment Co Collaborate 1

ID: 3606345 • Letter: U

Question

Untitled- Edited ST Insert Table Chart Text Shape Media Comment Co Collaborate 125% Zoom Bod Do the banner question from lab 3 but now, the banner must be printed in a function called printBanner. This function takes no input and returns nothing It prints the banner with a message as shown in the output below (similar message as in lab 3 banner). The function prompts the user to enter their first name, which is then printed in the banner. You may assume that the line of stars has 50 stars in it. Sample Input: Enter your first name: Dumbledore Output: Font Hel Reg Chara Welcome to week 7 lab Dumbledore Alignn @ e.*eee* e*eeeeeee.eeeeee e Spa Lines

Explanation / Answer

// ========================================================================== // Print Banner // ========================================================================== // Print a large banner version of a provided input string. // // Inf2C-CS Coursework 1. Task B // OUTLINE code, to be completed as part of coursework. // Paul Jackson // 8 Oct 2013 //--------------------------------------------------------------------------- // C definitions for SPIM system calls //--------------------------------------------------------------------------- #include int read_char() { return getchar(); } void read_string(char* s, int size) { fgets(s, size, stdin); } void print_char(int c) { putchar(c); } void print_string(char* s) { printf("%s", s); } //--------------------------------------------------------------------------- // Global variables //--------------------------------------------------------------------------- // Size of characters. // Use these constants where possible to ease reading and maintaining code #define NUM_COLS 4 #define NUM_ROWS 5 // Bit-patterns for each character. // For simplicity, just have here digits 0-9. unsigned int char_pats[] = { 0x69996, // 0 0x26227, // 1 0x6924f, // 2 0xe161e, // 3 0x26af2, // 4 0xf8e1e, // 5 0x78e96, // 6 0xf1248, // 7 0x69696, // 8 0x6971e // 9 }; // Other global variable declarations // TO BE COMPLETED //--------------------------------------------------------------------------- // PRINT_BITS //--------------------------------------------------------------------------- // Print bits n-1 ... 0 of input word w, using a '#' character for each 1 bit, // and a '.' character for each 0 bit. // Assume n > 0 void print_bits(unsigned int w, int n) { unsigned int mask = 0x1 > 1; } return; } //--------------------------------------------------------------------------- // GET_ROW_PATTERN //--------------------------------------------------------------------------- // Fetch pattern for row i of ASCII character c // If c is in the range of the ASCII codes for 0..9, the bit pattern for // the row is retrieved from the char_pats table. Otherwise, the function // always returns 0xf. // Rows of a character are numbered from 0, with 0 being the top row. // TO BE COMPLETED unsigned int get_row_pattern(char c, int i) { return 0xf; } //--------------------------------------------------------------------------- // MAIN function //--------------------------------------------------------------------------- // Prompt for input string up to 12 characters long and generate banner from it. // // If an optional program argument is provided, run a test of the // get_row_pattern() function instead. // // // A remark on handling of command line program arguments in C: // // argc is the number of command line arguments + 1. // argv is a pointer to an array of strings containing the program name and // each of the command line arguments. // If this program is compiled with // gcc -o banner banner.cc // Then // ./banner // gives argc == 1 // ./banner test // gives argc == 2. int main (int argc, char** argv) { unsigned int pat; if (argc > 1) { // Test code for get_row_pattern(). // Assumes print_bits() is functioning properly. // If all is good, this outputs the top 2 rows for character '4': // ....#. // ...##. // As '4' is not symmetric across horizontal or vertical axis, these // tests should catch errors where horizontal or vertical indexing is // reversed. unsigned int pat; pat = get_row_pattern('4', 0); print_bits(pat, NUM_COLS+2); print_char(' '); pat = get_row_pattern('4', 1); print_bits(pat, NUM_COLS+2); print_char(' '); print_char(' '); return 0; } // Main code // TO BE COMPLETED return 0; } //--------------------------------------------------------------------------- // End of file //---------------------------------------------------------------------------
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote