Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- //==========================================================================================================
- //Name: MathCon
- //Author: Craig D Cartwright
- //Version: 1.0
- //Copyright: CDC 2020
- //Description: A small console application performing mathematical operations
- //
- //===========================================================================================================
- #include <iostream>
- #include <algorithm>
- #include <stdio.h>
- #include <vector>
- using namespace std;
- void quick_sort(int[], int, int);
- int partition(int[], int, int);
- //Variables
- //const int SIZE = 50;
- string name; //A string called name which we can store a name
- int age; //A integer called age allowing to store a persons age
- int math; //A integer for the menu options
- int values;
- int CountNumbers;
- int largest;
- int smallest;
- int result;
- int i, max, min, size;
- int main()
- {
- //Code for entering and storing name
- cout << "Welcome, what is your name?\n"; //This asks the user their name and then indicates to start a new line (\n)
- cin >> name; //This takes the input from the previous line and stores in the name string.
- cout << "Thank you " << name << "! Welcome to the MathCon App" << endl; //
- //Code for entering and storing age
- cout << "How old are you " << name << "??\n"; //Asks user for their age
- cin >> age; //This takes the users age input and stores in the age integer
- cout << "Ah, so that means that you are " << age << " then " << name << "!\n"; //makes a comment about the age.
- //Code for entering integers into the console app
- int a[50], n, i; //Initalise an array for up to 50 integers
- cout << "How many Integers would you like to enter?\n";
- cin >> n;//Stores the user value into n
- cout << "Please enter your integers...\n";//asks the user to enter their chosen numbers...
- for (i = 0; i < n; i++)
- cin >> a[i];
- quick_sort(a, 0, n - 1);
- cout << "\nYour integers after sorting in ascending order are: " << endl;
- for (i = 0; i < n; i++)
- cout << a[i] << " " << endl;
- //Mathematical Operations
- cout << name << " please choose from the options below \n" << //This asks the user their name and then indicates to start a new line (\n)
- "1. Display the Count of the Integers input \n" <<
- "2. Display the Lowest and Highest Integers input \n" <<
- "3. Calculate the Range of the Integers input \n" <<
- "4. Calculate the Mean of the Integers input \n" <<
- "5. Calculate the Median of the Integers input \n" <<
- "6. Exit the program \n" <<
- "7. Enter new Integers \n";
- cin >> math;
- //Switch Decisions for Menu Options
- switch (math)
- {
- case 1: //Display the Count of the Integers Input
- {
- cout << "The Total Number of Integers entered is " << i << "\n";
- break;
- }
- case 2: //Display the Lowest and Highest Integers input
- vector<int> getLargestAndSmallestNumFromVector(vector<int> input) {
- int min = input[0];
- int max = input[0];
- for (int i = 0; i < input.size(); i += 1) {
- int checkSum = input[i];
- if (checkSum < min) {
- min = checkSum;
- }
- if (checkSum > max) {
- max = checkSum;
- }
- }
- vector<int> result;
- result.push_back(min);
- result.push_back(max);
- return result;
- }
- cout << "\nThe largest value entered is " << max << endl;
- cout << "\nThe smallest value entered is " << min << endl;
- }
- }
- }
- void quick_sort(int a[], int l, int u)
- {
- int j;
- if (l < u)
- {
- j = partition(a, l, u);
- quick_sort(a, l, j - 1);
- quick_sort(a, j + 1, u);
- }
- }
- int partition(int a[], int l, int u)
- {
- int v, i, j, temp;
- v = a[l];
- i = l;
- j = u + 1;
- do
- {
- do
- i++;
- while (a[i] < v && i <= u);
- do
- j--;
- while (v < a[j]);
- if (i < j)
- {
- temp = a[i];
- a[i] = a[j];
- a[j] = temp;
- }
- } while (i < j);
- a[l] = a[j];
- a[j] = v;
- return(j);
- }
- // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
- // Debug program: F5 or Debug > Start Debugging menu
- // Tips for Getting Started:
- // 1. Use the Solution Explorer window to add/manage files
- // 2. Use the Team Explorer window to connect to source control
- // 3. Use the Output window to see build output and other messages
- // 4. Use the Error List window to view errors
- // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
- // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement