Search for question
Question

Objectives: 1. Demonstrate the ability to code a program in C, emphasizing the utilization of arrays and function calls. 2. Apply the acquired knowledge of C programming concepts to create

functional and well-structured programs. 3. Explore debugging tools if desired, recognizing their potential benefits in program analysis and troubleshooting. 4. Master the translation of question requirements into actual functions within a C program. 5. Apply learned principles to efficiently convert specifications into executable code, showcasing a mastery of practical programming skills. Grading (The assignment is graded out of 100) Part I - 40 points(5 points for each question) Generate a single PDF file that includes all answers for this section. For each question: Provide a concise written response before you test it with the program. Develop a short program to validate the answer. If the output differs from the expected answer, analyze the code thoroughly. If they are the same, briefly explain how you generate the answers. O Submit a combination of text explanations and screenshots (if applicable) without submitting the code files. Grading Details: O Allocate 4 points for well-written text explanations that demonstrate a clear understanding of corresponding course materials relevant to the questions. o Assign 1 point for correctly identifying the answers. O O O Part II - 60 points (10 points for each question) For this section, write a short program for each given question. Adhere to reasonable C code formatting standards. (e.g. naming, spacing, and etc.) Submit both the .c files and, if applicable, .h files. No need to provide answers or explanations in this section; focus solely on functional C programs. • Grading Details: O Allocate 2 points for adherence to proper commenting standards throughout the code. O Award 6 points for the clarity and completeness of functions within the file. Consider aspects such as meaningful function names, appropriate parameter usage, and overall code structure. Assign 2 points for achieving the correct program output as per the specified requirements. O Part I (Write short answers) 1. Given the character assignments char x = 'f' and y = 'a', what will be the output of the following statement? printf("x=%c, y=%d \n", x-'c'+'C', x-y); printf(" y+2 = %c\n", y+2); 2. Given the float assignment float a = 3.14159;, what will be the output of the following statement? printf(" %5f|\n", a); printf("%5.1f|\n", a); printf(" |%5.4g|\n", a); printf("%10.1f|\n", a); printf(" %10.6g|\n", a); 3. Given the integer assignment int a = 3;, what will be the output of the following statement? } printf("%d\n", a*7+6%2/2); printf("%d\n", a++); printf("%d\n", a--); printf("%d\n", ++a); printf("%d\n", --a); 4. Determine the output of the following program: #include int main(){ int a = 5, b = 20; if (a&&b){ } if (allb){ } printf(" a&&b (5 & 20) -- True \n" ); printf(" al|b (5 || 20) -- True \n"); a = 0, b = 10; if (a&&b){ } printf(" a&&b (0 && 10) -- True \n" ); } if (al|b){ printf(" al|b (0 || 10) -- True \n" ); } if (!b){ printf(" !b (10) -- True \n"); 5. Given the integer assignments int a = 2, b = -1, c = 2, what will be the output of the following program? if (a } c=0; } c+=3; } int a = 12, b = 1; switch(a%3){ int main(){ 7. Determine the output of the following program: #include case 0: b+3; break; case 1: b--; break; case 2: b++; break; default: printf("Default.\n"); printf("%d\n", b); return 0; int a[] = {1,2,3,4,5}; printf("%ld\n", sizeof(a)); printf("%d\n", sizeof(a[1])); printf("%d", a[4]); return 0; 8. Determine the output of the following program: #include #include int main(){ char c[] = {'a','b','f','t', 'p','o'}; printf("%ld \n", sizeof(c)); printf("%c \n",c[1]); printf("%s\n", c + 2); return 0; Part II: Write a code based on the description 1. Write a program that takes any string input(less than 15 characters) and outputs the reversed version of the string. Hint: Use scanf(); 2. Develop a program that, given a three-digit number by the user, outputs its individual digits for units, tens, and hundreds. Hint: Use scanf(); Use / % to calculate the individual digits. 3. Input three integers from the user and calculate their sum, product, and difference. Hint: Use array 4. Input random four numbers from 1 to 9 by the user, and generate three digital numbers with no repeat number reused. Returns all the generated numbers, and returns how many in total. Hint: 1. Use array. 2. Functions transferring the parameters by reference. ● Declaration to get input from the user and store the values in an array void getlnput(int num[], int size); ● Declaration to generate three-digit numbers with no repeated digits using the given array int generateNum(int num[], int size); 5. Develop a program to determine baggage charges for passengers in the ordinary cabin of an airline, adhering to the following guidelines: a. The standard rate for the flight ticket is $120.0. b. Passengers are allowed to check in up to 20.0 kilograms of luggage for free. c. For weight exceeding 20.0 kilograms, a fee of 1.5% of the airline's standard rate is charged per kilogram. d. Calculate the baggage charges based on the given user input and determine the total charges(display the value in %.3f format) for the user by considering the flight ticket cost and baggage charges. 6. Write a program to print and count the "Narcissistic Numbers" between 100 and 999. Narcissistic Numbers are three-digit numbers where the sum of the cubes of their digits equals the number itself (e.g., 153 = 1^3+ 5^3+3^3). Example: student @ comp2401 : 16:00:15 ~/COMP2401/A1 # ./2_1 Enter a string: systemprograming Reversed string: gnimargorpmetsys student @ comp2401 : 16:00:26 ~/COMP2401/A1 # ./2_2 Please enter a three-digit number. 113 Hundreds: 1 Tens: 1 Units: 3 student @comp2401 : 16:00:40 ~/COMP2401/A1 # ./2_3 Please enter THREE numbers: 2 3 4 sum 9, product 24, different -5 student @ comp2401 : 16:02:16 ~/COMP2401/A1 # ./2_4 Please enter FOUR numbers (1-9): 1 2 3 4 Generated three-digit numbers: 123 124 132 134 142 143 213 214 231 234 241 243 312 314 321 324 341 342 412 413 421 423 431 432 We generate 24 in total.