-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
183 lines (137 loc) · 5.35 KB
/
Copy pathmain.cpp
File metadata and controls
183 lines (137 loc) · 5.35 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// ProblemSheet3, main.cpp
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// declarations
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void ReadInValueOne(long & a);
long GetLong(const std:: string & prompt);
int PauseAndReturn();
void PauseAndContinue();
double GetDouble(const std::string & prompt);
void ReadInValueTwo(double & b, double & c);
void ReadInValueThree(long & n);
double FunctionValue(double & b, double & c);
void print(std::string vec, long n, long i);
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// main()
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
int main(int argc, char *argv[])
{
long a; // For the first function
std::cout << "Hello and welcome to the Sam Harper Show! The first function will take your number and decide whether its divisbly by 3 but not by 2." << std::endl;
ReadInValueOne(a); // Reading Inputted function one value
if (a %3 == 0 && a %2 != 0)
{
std::cout <<"Bingo!" << std::endl;
}
else
{
std::cout << "Fooey!" << std::endl;
}
PauseAndContinue();
std::cout << "The next function takes your x and y computing and returning f(x) = y^2*x^2 + 13y*x^3 – 2x^4" << std::endl;
double b; //This is the x value
double c; //This is the y value
ReadInValueTwo(b, c); //I have created a different read in function as this function will be calling doubles not longs
long f = c*c * b*b + 13*c*b*b*b - 2*b*b*b*b;
std::cout << f << std::endl;
PauseAndContinue();
std::cout << "The next function takes your string x and prints it to console backwards" << std::endl;
long n = GetLong("Please enter a string to be printed backwards");
long reversedNumber = 0, remainder;
while(n != 0)
{
remainder = n %10;
reversedNumber = reversedNumber*10 +remainder;
n /= 10;
}
std::cout << "Reversed Number = " << reversedNumber << std::endl;
PauseAndContinue();
std::cout << "The last function takes your string and prints its n, 2n, 3n..... to console" << std::endl;
long q = GetLong("Please enter a string");
long p = GetLong("Enter n");
void print(q, p, p);
return PauseAndReturn();
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// ReadInValueOne()
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void ReadInValueOne(long & a) //Reading in value for function one
{
a = GetLong("Please enter a value for a");
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// ReadInValueTwo()
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void ReadInValueTwo(double & b, double & c) //Reading in value for function
{
b = GetDouble("Please enter a value for b");
c = GetDouble("Please enter a value for c");
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// ReadInValueThree()
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void ReadInValueThree(long n) //Reading in value for function three
{
n = GetLong("Please enter a string to be printed backwards");
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// GetLong()
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
long GetLong(const std:: string & prompt)
{
long value;
std::cout << prompt << ": ";
std::cin >> value;
return value;
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// GetDouble()
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
double GetDouble(const std::string & prompt)
{
double value;
std::cout << prompt << ": ";
std::cin >> value;
return value;
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// PauseAndReturn()
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
int PauseAndReturn()
{
char quit = '\0';
while (quit != 'q')
{
std::cout << "Enter q to quit: ";
std::cin >> quit;
}
return 0;
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// PauseAndContinue()
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void PauseAndContinue()
{
std::cout << "Press return to continue to next function" << std::endl;
std::cin.get();
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// print()
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void Print(std::string vec, long n, long i)
{
while (i < vec.size())
{
std::cout << vec.at(i-1) << std::endl;
i += n;
}
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// End of programme
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX