-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPTR141_A4.cpp
More file actions
160 lines (135 loc) · 4.32 KB
/
CPTR141_A4.cpp
File metadata and controls
160 lines (135 loc) · 4.32 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
/*****************************************************************************
Program file name: petedan.cpp OS: Mac OSX 10.4 Assignment #: 4
Programmer: Daniel Peterson Class: CPTR141 Date: 10-19-06
Compiler: Xcode 2.2.1
Assistance/references: Chris Wills
Description: menu system for 5 functions
Inputs: menu selection and ints
Outputs: mathematical relationships
Special Comments:
~~~~~~~~~~~~~~~~~~~~~~~~~~Grading Criteria~~~~~~~~~~~~~~~~~~~~~~~~~~
Assignment Requirements ___/3.0
Code Format/Cosmetics ___/3.0
Header & Code Comments: ___/2.0
Output Format/Cosmetics ___/2.0
***Does Not Compile***: ___ (-10.0)
***Late Work Deduction***: ___ (-0.5/day)
Total Grade: ___/10.0
*****************************************************************************/
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
void gcd()
{
int m,n,r = 0;
cout << "You have chosen to find the greatest common divisor of two positive integers." << endl;
cout << "Please enter your first integer: ";
cin >> m;
cout << "Please enter your second integer: ";
cin >> n;
while(m<0||n<0)
{
cout << "Your integers were not positive. Please try again." << endl;
cout << "Please enter your first integer: ";
cin >> m;
cout << "Please enter your second integer: ";
cin >> n;
}
r = m%n;
while(r!=0)
{
r = m%n;
m = n;
n = r;
}
cout << "The greastest common divisor is: " << m << endl;
}
void fact()
{
unsigned long long n = 1;
cout << "You have chosen to output n! to the largest possible value that's significant figures can be output on a PC" << endl;
for(int i=1;i*n >= n && i <= 20;i++)
{
n = i*n;
cout << n << endl;
}
}
void fibonacci()
{
long a=1;
long b=1;
long c=0;
cout << "You have chosen to output all Fibonacci numbers of type long." << endl;
while(a+b>b)
{
c=a+b;
a=b;
b=c;
cout << c << endl;
}
}
void abcd()
{
int a,b,c,d;
cout << "You have chosen to find four positive digits that satisfy A^B*C^D = ABCD" << endl;
for (a=1; a<=9; a++)
for (b=0; b<=9; b++)
for (c=1; c<=9; c++)
for (d=0; d<=9; d++)
if (pow(a,b)*pow(c,d) == 1000*a + 100*b + 10*c + d)
{
cout << "A = " << a << " B = " << b << " C = " << c << " D = " << d << endl;
return;
}
}
void diophantine()
{
int w,x,y,z;
cout << "You have chosen to find at least 8 solutions for the diophantine equation." << endl;
for(w=1;w<25;w++)
for(x=w;x<25;x++)
for(y=x;y<25;y++)
for(z=y;z*z*z <= w*w*w + x*x*x + y*y*y; z++)
if(z*z*z == w*w*w + x*x*x + y*y*y)
cout << "W = " << setw(2) << w << " X = " << setw(2) << x << " Y = " << setw(2) << y << " Z = " << setw(2) << z << endl;
}
int main (int argc, char * const argv[])
{
char choice;
cout << "Welcome to the mathematical formula program." << endl;
cout << "A. Find the greatest common divisor of to positive integers." << endl;
cout << "B. Output n! to the largest possible value to be held by a single variable on a pc." << endl;
cout << "C. Generate and output all Fibonacci numbers of type long." << endl;
cout << "D. Find 4 positive digits, A,B,C,D that satisfy: A^B*C^D = ABCD." << endl;
cout << "E. Find at least 8 unique solutions for 4 positive integers which satiisfy the diophantine equation." << endl;
cout << "Q. Quit." << endl;
cout << "Please choose an option: ";
cin >> choice;
choice = toupper(choice);
while (choice != 'Q')
{
switch (choice)
{
case 'A': gcd(); break;
case 'B': fact(); break;
case 'C': fibonacci(); break;
case 'D': abcd(); break;
case 'E': diophantine(); break;
default : cout << "Unrecognized selection. Please try again." << endl;
}
cout << "A. Find the greatest common divisor of to positive integers." << endl;
cout << "B. Output n! to the largest possible value to be held by a single variable on a pc." << endl;
cout << "C. Generate and output all Fibonacci numbers of type long." << endl;
cout << "D. Find 4 positive digits, A,B,C,D that satisfy: A^B*C^D = ABCD." << endl;
cout << "E. Find at least 8 unique solutions for 4 positive integers which satiisfy the diophantine equation." << endl;
cout << "Q. Quit." << endl;
cout << "Please choose an option: ";
cin >> choice;
choice = toupper(choice);
}
cout << "Thank you for using this program" << endl;
system("PAUSE");
return EXIT_SUCCESS;
}