-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunner.cpp
More file actions
130 lines (113 loc) · 3.83 KB
/
Copy pathRunner.cpp
File metadata and controls
130 lines (113 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
// Runner.cpp
// Project 5 - Templates
//
// Created by Amarjot Gill 4/26/2021
// Runner class for vector class includes a menu for user to select options
#ifndef RUNNER_CPP
#define RUNNER_CPP
#include <cstdlib>
#include "Vector.cpp"
using namespace std;
const int THREE = 3;
const int FOUR = 4;
const int FIVE = 5;
const int SIX = 6;
const int SEVEN = 7;
const int EIGHT = 8;
const int NINE = 9;
template <class T>
class Runner {
public:
// Name: Default Constructor
// Precondition: None
// Postcondition: Initiates state/environment
Runner(Vector<T>*, Vector<T>*);
// Name: mainMenu
// Desc: Main Menu
// Precondition: Existing Vectors
// Postcondition: Handles various menu commands
int mainMenu();
private:
Vector<T> m_vector1;
Vector<T> m_vector2;
};
// **** Add class definition below ****
template <class T>
Runner<T>::Runner(Vector<T>* vec_one, Vector<T>* vec_two){
bool keepRunning = true;
// creates two new Vectors using copy constructors
Vector<T> *m_vector1 = new Vector<T>(*vec_one);
Vector<T> *m_vector2 = new Vector<T>(*vec_two);
do{
int option = mainMenu();
if (option == ONE){
cout << "Vector 1: ";
m_vector1->Display();
cout << endl;
cout << "Vector 2: ";
m_vector2->Display();
cout << endl;
}else if (option == TWO){
cout << "Vector 1 < Vector 2: ";
Vector<char> *temp = *m_vector1 < *m_vector2;
temp->Display();
delete temp;
temp = nullptr;
}else if(option == THREE){
cout << "Vector 1 == Vector 2: ";
Vector<char> *temp = *m_vector1 == *m_vector2;
temp -> Display();
delete temp;
temp = nullptr;
}else if(option == FOUR){
cout << "Vector 1 + Vector 2: ";
// sets temp to the result vector
Vector<T> *temp = *m_vector1 + *m_vector2;
temp -> Display();
// deletes since it was dynamically allocated
delete temp;
temp = nullptr;
}else if(option == FIVE){
cout << "Vector 1 * Vector 2: ";
Vector<T> *temp = *m_vector1 * *m_vector2;
temp -> Display();
// deletes because it was dynamically allocated
delete temp;
temp = nullptr;
}else if(option == SIX){
cout << "Vector 1 median: " << m_vector1->Median() << endl;
cout << "Vector 2 median: " << m_vector2->Median() << endl;
}else if(option == SEVEN){
cout << "Vector 1 mean: " << m_vector1->Mean() << endl;
cout << "Vector 2 mean: " << m_vector2->Mean() << endl;
}else if(option == EIGHT){
cout << "Vector 1 StDev: " << m_vector1->StDev() << endl;
cout << "Vector 2 StDev: " << m_vector2->StDev() << endl;
// if user selects nine the loop ends and program ends
}else if(option == NINE){
keepRunning = false;
}
} while (keepRunning);
// deletes the dynamically allocated vectors
delete m_vector1;
delete m_vector2;
}
template <class T>
int Runner<T>::mainMenu(){
int option;
cout << "Choose an option" << endl;
cout << "1. Display Vectors" << endl;
cout << "2. Vector Comparison (<)" << endl;
cout << "3. Vector Compaison (==) " << endl;
cout << "4. Vector addition" << endl;
cout << "5. Vector multiplication " << endl;
cout << "6. Compute median" << endl;
cout << "7. Compute mean "<< endl;
cout << "8. Compute Standard Derivation" << endl;
cout << "9. Exit" << endl;
cin >> option;
// returns whatever number user selects will bounds check in constructor
return option;
}
#endif /* Runner_h */