Recursion program to find the greatest common divisor(update latter)
#include <cstdlib>
#include <iostream>
using namespace std;
int gcd(int a, int b);
int main(int argc, char *argv[])
{
int larger;
int smaller;
int temp;
cout << "Hello, "
<< endl;
cout << "This program will calculate the greatest common divisor"
<< endl;
cout << "Please enter a first number number: "
<< endl;
cin >> smaller;
cout << "Please enter a second number: "
<< endl;
cin >> larger;
cout << gcd(smaller, larger) << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
int gcd(int smaller, int larger)
{
int temp;
int rem;
if (smaller > larger)
{
temp = larger;
larger = smaller;
smaller = temp;
}
rem = larger % smaller;
if (rem == 0)
//if rem >9000....
return smaller;
else
return(smaller, rem);
}
Wednesday, October 5, 2011
Wednesday, September 14, 2011
9/14
I got my laptop back today. A circuit in the hard drive severed, which made it unusable; so I did a fresh install of windows 7. Also something I didn't do was have a back up, which is pretty much a given for anyone in IT...guess I'm not in IT....
At the moment I have a few programs are up and running, mostly personal items, bur all the updates, drivers and such are done.
If I havn't put it down yet, I got my new schedule for school; my classes for this semester are as follows: Web technologies, programming 2 and inter-cultural communications.
I'M rather looking forward to it, in Web tech I'm going to start PHP. Its one of the languages I've seen almost universally through out applications. I was talking to a few friends who are in the IT field, and 2 of the 3 said that C++ is out of date as far as programming goes, and that most companies use ASP .net or Java(Script).
Inter-cultural leads to most psychology classes, which if anything is something like a minor for me(we dont have minors at MSB)
Note:
Since my old drive is fried I lost all my previous school work. I do beileve that I have a paper copy of my report on social media, I'll have to look around.
Note 2:
I start next semester on Oct, 8th. And I now have a hard drive to back up my laptop...
At the moment I have a few programs are up and running, mostly personal items, bur all the updates, drivers and such are done.
If I havn't put it down yet, I got my new schedule for school; my classes for this semester are as follows: Web technologies, programming 2 and inter-cultural communications.
I'M rather looking forward to it, in Web tech I'm going to start PHP. Its one of the languages I've seen almost universally through out applications. I was talking to a few friends who are in the IT field, and 2 of the 3 said that C++ is out of date as far as programming goes, and that most companies use ASP .net or Java(Script).
Inter-cultural leads to most psychology classes, which if anything is something like a minor for me(we dont have minors at MSB)
Note:
Since my old drive is fried I lost all my previous school work. I do beileve that I have a paper copy of my report on social media, I'll have to look around.
Note 2:
I start next semester on Oct, 8th. And I now have a hard drive to back up my laptop...
Wednesday, August 31, 2011
8/31!!
So I took my laptop in, as I thought it wasn't anything I could fix...the LCD was, for lack of a better word, broken. The other issue that was wrong with it is that when you started up the computer it would cycle between the gateway screen and a courser, their looking looking into what is causing this, they think it may be something to do with the hard drive. I originally thought it may have something to do with the bios...
As for the summer, I didnt do much with programming; I did finally install a sound card in my desktop as well as get a second monitor...which is something I've been wanting to do for awhile now. I 'll upload a picture(maybe) sometime.
As for the summer, I didnt do much with programming; I did finally install a sound card in my desktop as well as get a second monitor...which is something I've been wanting to do for awhile now. I 'll upload a picture(maybe) sometime.
Friday, August 26, 2011
8/26!!!
Its been awhile....
My laptop took a dive into the floor, I took it apart to see if anything hardware related was broken, or I could fix, but it doesn't look like it so im taking it into a tech shop Monday.
Class is starting in about 5 weeks...I got my schedule a few days ago. I have Web technologies, Programming 2 and Intercultural Communications. Its rather different than last semester, where I had 2 Business classes on campus and one IT class online.
I'm looking forward to this semester since I have all 3 classes on Campus, one im pretty sure will be taught by a instrucer I've had before(Richard Cummings) and one which is a pre-req to psychology classes, which I would consider something of a minor...but we dont have established minors at MSB.
My laptop took a dive into the floor, I took it apart to see if anything hardware related was broken, or I could fix, but it doesn't look like it so im taking it into a tech shop Monday.
Class is starting in about 5 weeks...I got my schedule a few days ago. I have Web technologies, Programming 2 and Intercultural Communications. Its rather different than last semester, where I had 2 Business classes on campus and one IT class online.
I'm looking forward to this semester since I have all 3 classes on Campus, one im pretty sure will be taught by a instrucer I've had before(Richard Cummings) and one which is a pre-req to psychology classes, which I would consider something of a minor...but we dont have established minors at MSB.
Tuesday, June 21, 2011
June 21
Been very busy between research papers and presentations I had to make for school, I'll get a post on what ive been doing late this week or early next week.
Tuesday, June 7, 2011
We have been discussing arrays in the past week.
Our assignment was to create a program that took the first and last name of the user and output it in reverse order.
cout << "please enter your first name: " << endl;
char str1[30];
cin >> str1;
cout << "please enter your last name: " << endl;
char str2[20];
cin >> str2;
cout << "Your name before manipulation: " << str1 << " " << str2 << endl;
cout << "your name after: " << str2;
strcpy(str2, str1);
cout << " " << str2 << endl;
comments:
I could have eliminated 2 separate lines for the cin input, and just did,
cin >> str1 >> str2
char str1[30];
char str2[25];
or something close to that.
I also feel it kind of redundant the way we have to reverse order.
Cout str2 and then copy the value of str1 into str2 and output it again.
A better way I think is we could just cout >> str2 >> str1
This eliminates extra code, along with if you have to use str2 again latter on the in the program you can use it as the "real" value of str2
Our assignment was to create a program that took the first and last name of the user and output it in reverse order.
cout << "please enter your first name: " << endl;
char str1[30];
cin >> str1;
cout << "please enter your last name: " << endl;
char str2[20];
cin >> str2;
cout << "Your name before manipulation: " << str1 << " " << str2 << endl;
cout << "your name after: " << str2;
strcpy(str2, str1);
cout << " " << str2 << endl;
comments:
I could have eliminated 2 separate lines for the cin input, and just did,
cin >> str1 >> str2
char str1[30];
char str2[25];
or something close to that.
I also feel it kind of redundant the way we have to reverse order.
Cout str2 and then copy the value of str1 into str2 and output it again.
A better way I think is we could just cout >> str2 >> str1
This eliminates extra code, along with if you have to use str2 again latter on the in the program you can use it as the "real" value of str2
Wednesday, June 1, 2011
June 1!!!
We user defined simple data and string types(last week) this week we are working with arrays.
In Chapter 8, there is a discussion of the "Rock, Paper, Scissors" game. Discuss how this game works, and how a C++ program that models this game will use a variety of types.
(may have done this wrong)
First it defines the object rock, paper, and scissor.
After that the function prototypes are defined.
Displayrules are called upon entering the game and display the Cout statements on page 446.
Objecttype gets the keystroke that the user entered through a switch structure. It uses both uppercase and lowercase to decide. To passes the object that was selected to gameresults.
Gameresults, this calls winningobject to decide how the game should go; or, the truth table for the game.
After the truth table is found, it proceeds through game results first to see if the game is a tie, then it outputs each player’s choice. It then compares each player’s objects that they chose to the winningobject, via the convertenum function, and outputs the winner.
The convert enum function converts each of the enum defined(rock, paper, scissors) to something that can be recognized by C++(a cout statement)
Display results outputs the number of games played and who many times each player has won a game, the wins for player one is stored in wCount1 and the wins for player 2 is stored in wCount2. The loop for incrementing each counting sequence is in the main body of the program.
comment by instructor: Great job in breaking this down here, with "enum" in this case, would this be a function? How would this be defined?
my response:
If I understand your question correctly, no, the:
enum objectType {rock, paper, scissors}
is no a function.
enum does nothing more than create a user defined data type.
So instead of
char rock, paper, scissors;
you have enum ObjecType {rock...ect
This is the reason you have to have a new function to "read" the data in the enum. Which is where the convert enum function comes into play(on page 449)
To define an enum data type use the following code:
enum TypeName {value1, value2, ect}
In Chapter 8, there is a discussion of the "Rock, Paper, Scissors" game. Discuss how this game works, and how a C++ program that models this game will use a variety of types.
(may have done this wrong)
First it defines the object rock, paper, and scissor.
After that the function prototypes are defined.
Displayrules are called upon entering the game and display the Cout statements on page 446.
Objecttype gets the keystroke that the user entered through a switch structure. It uses both uppercase and lowercase to decide. To passes the object that was selected to gameresults.
Gameresults, this calls winningobject to decide how the game should go; or, the truth table for the game.
After the truth table is found, it proceeds through game results first to see if the game is a tie, then it outputs each player’s choice. It then compares each player’s objects that they chose to the winningobject, via the convertenum function, and outputs the winner.
The convert enum function converts each of the enum defined(rock, paper, scissors) to something that can be recognized by C++(a cout statement)
Display results outputs the number of games played and who many times each player has won a game, the wins for player one is stored in wCount1 and the wins for player 2 is stored in wCount2. The loop for incrementing each counting sequence is in the main body of the program.
comment by instructor: Great job in breaking this down here, with "enum" in this case, would this be a function? How would this be defined?
my response:
If I understand your question correctly, no, the:
enum objectType {rock, paper, scissors}
is no a function.
enum does nothing more than create a user defined data type.
So instead of
char rock, paper, scissors;
you have enum ObjecType {rock...ect
This is the reason you have to have a new function to "read" the data in the enum. Which is where the convert enum function comes into play(on page 449)
To define an enum data type use the following code:
enum TypeName {value1, value2, ect}
Subscribe to:
Posts (Atom)