{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

homework_4

# homework_4 - ECE 1574 Homework Set#4 Problem Solving with C...

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

ECE 1574 Homework Set #4 Problem Solving with C++ Due date: 2/14/10 by 11:55PM This assignment is to be done individually Solve problems 1 through 5 during the lab session. Work the additional exercises later. 1. Ask the user to enter two characters. Then use the relational greater than operator to compare the two characters and output whether or not the first character entered is greater than or less than the second character entered . #include <iostream> #include <cmath> using namespace std; void main() { double x; double y; cout << "Enter two digits that you want to compare." << endl; cin >> x; cin >> y; if (x>y) { cout << x << " is greater than " << y << endl; } if (x<y) { cout << y << " is greater than " << x << endl; } if (x==y) { cout << "Both numbers are the same." << endl; } } 2. Ask the user to enter a string then count and output the number of x's and 0's (zero and not character O) that occur in the string. #include <iostream> #include <cmath> #include <string> #include <iomanip> using namespace std; int main() { string text; char letter1 = 't' ;

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

View Full Document
char letter2 = '0' ; int count = 0; int count2 = 0; int x=2; cout << "Press enter to start the program. =]" ; while (x>1) { count = 0; count2 = 0; cin.ignore(100, '\n' ); cout << "Enter a string of your choice: " ; getline(cin, text); for ( unsigned int i =0; i < text.length(); i++) { if (text[i] == letter1) count++; } for ( unsigned int i =0; i < text.length(); i++) { if (text[i] == letter2) count2++; } cout<< "The letter "
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

homework_4 - ECE 1574 Homework Set#4 Problem Solving with C...

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

View Full Document
Ask a homework question - tutors are online