Midterm+1-Solution

# Midterm+1-Solution - ECE3090 Software for Engineering...

This preview shows pages 1–5. Sign up to view the full content.

- 1 - ECE3090 Software for Engineering Systems Fall 2009 School of Electrical and Computer Engineering Georgia Institute of Technology - Savannah Midterm 1 (10/01/2009) 3:05 – 4:25 pm Open book and notes Total points: 100

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
- 2 - Name: Total Scores: Problem 1 Problem 2 Problem 3 Problem 4
- 3 - Problem 1 (30 points). Each of the following programs or program segments has errors. Find as many errors as you can and correct them based on the description in the comment lines. (a) (5 points) /* Compare the content of the character array str against a character array literal “ STOP ”. If they are the same regardless the case of each letter, then exit from the progam. */ char str[] = “Stop”; if (isupper(str) == “STOP”) exit (0); // isupper works for characters, not character strings; // string comparison should be through strcmp. // Convert each and every letter of str to upper-case. for (int index=0; index<strlen(str); index++) str[index] = toupper(str[index]); // Compare the upper-cased str with "STOP". if (strcmp(str, "STOP") == 0) exit (0); (b) (5 points) /* Compare the contents of string1 and string2 . If they are different, then concatenate the content of string2 to the end of string1 .*/ char string1[] = “Billy”; char string2[] = “Bob Jones”; if (string1 != string2) strcat(string1, string2); // string1 does not have enough memory space to hold the concatenated string. // String comparison should be through strcmp. Char string1[100] = “Billy”; if (strcmp(string1, string2)) strcat(string1, string2);

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
- 4 - (c) (10 points) /*This program gets a series of floating point numbers from a user, and calculates the average of these numbers. Getting numbers and calculating the average are implemented through functions. */ #include <iostream> using namespace std; // Functions must be declared or defined before being called. float GetANumber(); float CalculateAverage(float *, int); int main() { int number_of_data; cout << “For how many data would you like to calculate the average?\n”; cin >> number_of_data; float data[number_of_data]; // The size-declarator cannot be a variable.
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/24/2009 for the course ECE 3090 taught by Professor Staff during the Fall '08 term at Georgia Tech.

### Page1 / 16

Midterm+1-Solution - ECE3090 Software for Engineering...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online