homework4-godara

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

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 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() {
Background image of page 1

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

View Full DocumentRight Arrow Icon
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. Create a table of the values of cos(theta) values where theta varies from zero degrees to
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.

Page1 / 6

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

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