ENEE 114 Quiz 3 Solutions, Quizzes of Electrical and Electronics Engineering

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

2019/2020

Uploaded on 11/25/2020

koofers-user-td0-2
koofers-user-td0-2 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
qz3p1Soln.txt:
ENEE 114 Section 0101
Quiz 3 Problem 1 Solution
1. In C, two user-defined functions CAN have the same
name. (True/False)
Ans: False
2. Name three functions that you used in the first two homework
assignments
Ans: a) main
b) scanf
c) printf
3. The input to a function has no bearing on its outputed return
type. (True/False)
Ans: True
4. The arguments to a function can be passed in two ways.
They are pass-by-____ and pass-by-_________
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:
-----------
pf3
pf4

Partial preview of the text

Download ENEE 114 Quiz 3 Solutions and more Quizzes Electrical and Electronics Engineering in PDF only on Docsity!

qz3p1Soln.txt:

ENEE 114 Section 0101 Quiz 3 Problem 1 Solution

  1. In C, two user-defined functions CAN have the same name. (True/False)

Ans: False

  1. Name three functions that you used in the first two homework assignments

Ans: a) main b) scanf c) printf

  1. The input to a function has no bearing on its outputed return type. (True/False)

Ans: True

  1. The arguments to a function can be passed in two ways. They are pass-by-____ and pass-by-_________

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'; }