


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The solutions to quiz 3 of the enee 114 course. It includes the answers to multiple-choice questions and the code for solving a problem where the user is asked to write functions to read a string from the user, print it out backwards with the cases of all the alphabets switched, and earn a total of 13 points.
Typology: Quizzes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



qz3p1Soln.txt:
ENEE 114 Section 0101 Quiz 3 Problem 1 Solution
Ans: False
Ans: a) main b) scanf c) printf
Ans: True
Ans: a) value b) reference
qz3p2Soln.c:
/* ENEE 114 Section 0101 Quiz 3 Problem 2 Solution */
// A program to read in a string from the user and print it out backwards // with the cases of all the alphabets switched
// You will write the functions based on the prototypes and decsriptions // provided below
/* NOTE 1: You may add code only where it says: "Write the code for the function here" You may not modify any other part of this file
NOTE 2: Except scanf, you can NOT use any of the other functions from any of the standard libraries
NOTE 3: Your program should not produce ANY warnings when compiled
You might want to compile and run this program to make sure that all the functions work correctly */
/* Sample Run:
Enter the string: This will produce GARBAGE when put in as Input! The reversed string with cases switched is:! TUPNi SA NI TUP NEHW egabrag ECUDORP LLIW SIHt */
#include <stdio.h>
// Function prototypes for the functions
int isAlpha( char c ); <-- 2 points int isUpper( char c ); <-- 1 point int isLower( char c );
char toUpper( char c ); char toLower( char c ); <-- 1 point
char switchCase( char c ); <-- 3 points
int stringLength( char string[] ); <-- 3 points void getString( char string[] ); <-- 3 points
Total = 13 points
// The main() function
int main( void ) { char string[80]; int size;
printf("%s", "\nEnter the string: "); getString(string);
size = stringLength(string);
printf("%s", "The reversed string with cases switched is: ");
// The for loop that prints the string in reverse for( --size ; size >=0 ; size-- ) { printf("%c", switchCase( string[size] ) ); } printf("\n");
return 0; }
/---------------------------------------------------- The "isAlpha" function Returns 1 if the character inputed is an alphabet. Returns 0 otherwise -----------------------------------------------------/ int isAlpha( char c ) { if( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) ) return 1;
return 0;
char answer;
if( isAlpha( c ) ) { if( isUpper( c ) ) answer = toLower( c );
if( isLower( c ) ) answer = toUpper( c ); } else answer = c;
return answer; }
/---------------------------------------------------- The "stringLength" function Returns the number of characters that appear in the string passed in, before the first null character is seen. ----------------------------------------------------/ int stringLength( char string[] ) { int index = 0; while( string[index] != '\0' ) index++;
return index; }
/---------------------------------------------------- The "getString" function Reads characters into the string passed in (beginning from the position string[0]) untill a new line character is seen in the input. Puts the null character in the string where the new line character would have been. ----------------------------------------------------/ void getString( char string[] ) { int index = 0;
scanf("%c", &string[index] );
while( string[index] != '\n' ) { index++; scanf("%c", &string[index] ); }
string[index] = '\0'; }