heimsventus

Dailies 4

Apr 14th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.54 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include <iostream>
  4. #include <cmath>
  5. #include <string>
  6. #include <fstream>
  7. #include <vector>
  8. #include <sstream>
  9. #include <fstream>
  10.  
  11. using namespace std;
  12. string convert2Lower(string phrase) {
  13.     string returnString = "";
  14.     for (int i = 0; i < size(phrase); i++)
  15.     {
  16.         returnString += tolower(phrase[i]);
  17.     }
  18.  
  19.     return returnString;
  20. }
  21.  
  22.  
  23. void printSepartaor(int separatorNumber) {
  24.     cout << "-------------This is the end of #" << separatorNumber << " of Dailies 4." << endl;
  25.  
  26. }
  27. int main()
  28. {
  29.  
  30.     printSepartaor(1);
  31.  
  32.     int values[10] = { 100234, 23, -5232, 996, 242, 24, 5239, -15, 336, 29 };
  33.     int sum = 0;
  34.     int average = 0;
  35.     int min = 0, max = 0;
  36.     for (size_t i = 0; i < 10; i++)
  37.     {
  38.         sum = sum + values[i];
  39.         if (values[i] > max)
  40.         {
  41.             max = values[i];
  42.         }
  43.         if (values[i] < min)
  44.         {
  45.             min = values[i];
  46.         }
  47.  
  48.  
  49.     }
  50.     average = values[10] / 10;
  51.  
  52.     cout << " The sum is " << sum << ", the max is " << max << ", " << "the min is " << min << ", and the average is " << average << "." << endl;
  53.  
  54.     printSepartaor(2);
  55.  
  56.     for (size_t i = 0; i < 9; i++)
  57.     {
  58.  
  59.  
  60.         for (size_t j = i + 1; j < 10; j++)
  61.         {
  62.             int temp = 0;
  63.             if (values[i] > values[j])
  64.             {
  65.                 temp = values[i];
  66.                 values[i] = values[j];
  67.                 values[j] = temp;
  68.             }
  69.  
  70.  
  71.         }
  72.  
  73.     }
  74.     cout << "The values in ascending order are: " << endl;
  75.     for (int i = 0; i < 10; i++)
  76.     {
  77.         cout << values[i] << " ";
  78.     }
  79.     cout << endl;
  80.     printSepartaor(3);
  81.  
  82.  
  83.     ifstream inputFile;
  84.     inputFile.open("C:\\Users\cis.LABS\Downloads\\rainfall.txt", ios::in);
  85.     if (!inputFile.is_open()) {
  86.         cout << "File could not be opened.\n\n";
  87.         system("pause");
  88.         return 1;
  89.     }
  90.     else {
  91.         cout << "File was opened properly.\n\n";
  92.     }
  93.     ifstream fin("rainfall.txt");
  94.     double number = 0.0, sumtwo = 0.0, averagetwo = 0.0;
  95.     int count = 0;
  96.     double arrayvalues[100000];
  97.     do
  98.     {
  99.         fin >> number;
  100.         sumtwo = sumtwo + number;
  101.         count++;
  102.  
  103.  
  104.     } while (number != -999);
  105.  
  106.     averagetwo = sumtwo / count;
  107.     cout << "The average is " << averagetwo << endl;
  108.     printSepartaor(4);
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.     string phrasetwo;
  117.     int countVowels = 0;
  118.     char lettertwo;
  119.     cout << "Enter a phrase. " << endl;
  120.     getline(cin, phrasetwo);
  121.     int countWords = 0;
  122.     istringstream phraseStream(phrasetwo);
  123.     string wordstwo;
  124.     while (getline(phraseStream, wordstwo, ' '))
  125.         {
  126.         countWords++;
  127.         }
  128.  
  129.  
  130.     for (int i = 0; i <phrasetwo.size(); i++)
  131.     {
  132.         lettertwo = phrasetwo.at(i);
  133.         if (lettertwo == 'a' || lettertwo == 'e' || lettertwo == 'i' || lettertwo == 'o' || lettertwo == 'u' || lettertwo == 'y')
  134.         {
  135.             countVowels++;
  136.         }
  137.  
  138.     }
  139.  
  140.  
  141.  
  142.  
  143.     cout << "The number of vowels are " << countVowels << " and the number of words are " << countWords << "." << endl;
  144.  
  145.  
  146.  
  147.  
  148.     printSepartaor(5);
  149.  
  150.     string str1("The brown FOX jumped over the Lazy dog");
  151.     string str2 = convert2Lower(str1);
  152.  
  153.     istringstream iss(str1);
  154.  
  155.     while (iss) {
  156.         string word;
  157.         iss >> word;
  158.  
  159.         int wordSize = size(word);
  160.         char firstLetter = tolower(word[0]);
  161.         switch (firstLetter)
  162.         {
  163.         case 'a':
  164.         case 'e':
  165.         case 'i':
  166.         case 'o':
  167.         case 'u':
  168.             word += "way";
  169.             cout << word << endl;
  170.             break;
  171.         default:
  172.             for (int i = 0; i < wordSize; i++)
  173.             {
  174.                 char letter = tolower(word[i]);
  175.                 if (letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u' || letter == 'y')
  176.                 {
  177.                     string prefix = word.substr(0, i);
  178.                     prefix += "ay";
  179.                     word.erase(0, i);
  180.                     word += prefix;
  181.  
  182.                     cout << word << endl;
  183.                     break;
  184.                 }
  185.             }
  186.             break;
  187.         }
  188.  
  189.     }
  190.  
  191.  
  192.     printSepartaor(6);
  193.     system("pause");
  194.     return 0;
  195. }
Advertisement
Add Comment
Please, Sign In to add comment