Advertisement
heimsventus

Dailies 4 incomplete number 5

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