homework4-godara

# homework4-godara - ECE 1574 Homework Set#4 TANUJ GODARA...

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

ECE 1574 Homework Set #4 TANUJ GODARA 9052-79307 Problem Solving with C++ Due date: 2/14/10 by 11:55PM 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() {

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

View Full Document
string text; char letter1 = 't' ; 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 " <<count<< " times in the text." <<endl; cout<< "The number " <<letter2<< " occurs " <<count2<< " times in the text." <<endl; break ; } return 0; } 3.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern