Advertisement
heimsventus

untitled

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