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

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

View Full Document Right Arrow Icon
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' ;
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 " <<letter1<< " occurs "
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/14/2010 for the course COMM 2064 taught by Professor Jimkuypers during the Spring '08 term at Virginia Tech.

Page1 / 5

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online