Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cctype>
- #include <fstream>
- using namespace std;
- void task1()
- {
- char symbol;
- cout << "Enter words (@ to abort): ";
- while (cin >> symbol)
- {
- if (symbol == '@') break;
- if (isalpha(symbol))
- {
- if (isupper(symbol))
- symbol = tolower(symbol);
- else
- symbol = toupper(symbol);
- cout << symbol;
- }
- }
- }
- void task2()
- {
- double mas[10];
- int mascount = 0;
- cout << "Enter up to 10 numbers: ";
- for (mascount; !cin.fail() && mascount < 10; mascount++)
- {
- cin >> mas[mascount];
- }
- if (mascount < 10)
- {
- cin.clear();
- cin.ignore();
- }
- double average = 0;
- for (int i = 0; i < mascount; i++)
- {
- average += mas[i];
- }
- average /= --mascount;
- int count = 0;
- for (int i = 0; i < mascount; i++)
- {
- if (mas[i] > average) count++;
- }
- cout << "Average: " << average << endl;
- cout << "Count of numbers that > average: " << count << endl;
- }
- void task3()
- {
- string word;
- int vowel = 0, consonants = 0, other = 0;;
- cout << "Enter words(q to quit): ";
- while (cin >> word)
- {
- if (word == "q") break;
- if (isalpha(word[0]))
- {
- switch (word[0]) {
- case 'a': case'e': case'i': case 'o': case 'u': case 'A': case'E': case'I': case 'O': case 'U':
- vowel++;
- break;
- default: consonants++;
- }
- }
- else other++;
- }
- cout << vowel << " words beginning with vowels\n";
- cout << consonants << " words beginning with consonants\n";
- cout << other << " other\n";
- }
- void task4()
- {
- fstream fin;
- fin.open("C:/Users/Student.DESKTOP-9N1N9O3/Desktop/file.txt");
- while (!fin)
- {
- cerr << "File doesn't open!\n";
- cout << "Enter new file adress or \"e\" to abort: ";
- string new_file;
- cin >> new_file;
- if (new_file == "e") return;
- fin.open(new_file);
- }
- char stuff;
- int count = 0;
- while (fin >> stuff)
- count++;
- fin.close();
- cout << count;
- }
- double add(double lval, double rval)
- {
- return lval + rval;
- }
- double remove(double lval, double rval)
- {
- return lval - rval;
- }
- double multi(double lval, double rval)
- {
- return lval * rval;
- }
- double ost(double lval, double rval)
- {
- if (int(lval) != lval || int(rval) != rval)
- {
- cerr << "Numbers aren't integer!\n";
- return 0;
- }
- return int(lval) % int(rval);
- }
- double calculate(double lval, double rval, double (*f)(double, double))
- {
- return f(lval, rval);
- }
- void task5()
- {
- double lval, rval;
- string key;
- cout << "Non-value input will end the program.\n";
- while (true)
- {
- cout << "Enter 2 values: ";
- cin >> lval >> rval;
- if (cin.fail())
- {
- cout << "ended.";
- break;
- }
- const size_t arr_size = 4;
- double((*arr[arr_size]))(double lval, double rval);
- string func_name[arr_size];
- arr[0] = add; arr[1] = remove; arr[2] = multi; arr[3] = ost;
- func_name[0] = "add"; func_name[1] = "remove"; func_name[2] = "multi"; func_name[3] = "ost";
- for (int i = 0; i < arr_size; i++)
- cout << endl << "Result of " << func_name[i] << ": " << calculate(lval, rval, arr[i]) << endl;
- cout << endl;
- }
- }
- int main()
- {
- task2();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement