include iostream include cctype include cstring using namespace std int

Include iostream include cctype include cstring using

This preview shows page 6 - 9 out of 10 pages.

#include <iostream> #include <cctype> #include <cstring> using namespace std; int main(void) { int count[26] = {0}; char sentence[81]; int i, len, index; cout << "Enter a sentence: "; cin.getline(sentence, 81); len = strlen(sentence); for (i=0; i<len; i++) { if (isalpha(sentence[i])) { index = tolower(sentence[i]) - 97; count[index]++; } } cout << "The count for each letter is:\n"; for (i=0; i<26; i++) cout << (char)(i+97) << "\t" << count[i] << endl; return 0; } 13. #include <iostream> 6
Image of page 6
UECS1643 Fundamentals Of Programming #include <iomanip> using namespace std; struct POINT { double x_coord ; double y_coord; }; int main(void) { struct POINT p1, p2, midpoint; cout << "Enter coordinates for p1: "; cin >> p1.x_coord >> p1.y_coord; cout << "Enter coordinates for p2: "; cin >> p2.x_coord >> p2.y_coord; midpoint.x_coord = (p1.x_coord + p2.x_coord) / 2; midpoint.y_coord = (p1.y_coord + p2.y_coord) / 2; cout << "The midpoint of p1 and p2: (" << fixed << setprecision(1) << midpoint.x_coord << ", " << midpoint.y_coord << ")\n"; return 0; } 14. #include <iostream> #include <iomanip> using namespace std; struct TIME { int hour; int minute; }; int main() { struct TIME time; cout << "Enter current time hours and minutes:"; cin >> time.hour >> time.minute; time.minute ++; if (time.minute == 60) { time.minute -= 60; time.hour++; if (time.hour > 12) time.hour -= 12; } cout << "\nThe time one minute later: " << setfill('0') << setw(2) << time.hour << ":" << setw(2) << time.minute << endl; return 0; } 15. #include <iostream> 7
Image of page 7
UECS1643 Fundamentals Of Programming using namespace std; typedef struct { int numerator; int denominator; } FRACTION; FRACTION get_fraction (void); void print_fraction (FRACTION f); FRACTION reduce (FRACTION f); int main(void) {
Image of page 8
Image of page 9

You've reached the end of your free preview.

Want to read all 10 pages?

  • Spring '15
  • Summation, Carriage return, Mathematics in medieval Islam

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture