Powered by Invision Power Board

 
  Pages: (10) 1 2 [3] 4 5 ... Last » ( Go to first unread post ) Reply to this topicStart new topicStart Poll

> Giygas learns the art of C++
United States
Giygas
Posted: Sep 24 2009, 07:31 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


user posted image
So uh, yeah, may seem wierd that i'm posting an "update" on a DOS calculator but
I made the answers and input questions less wordy and more to the point, also changed the layout to make it easier to see which number for which command. Aso added square root.
Other than add a few more commans, I don't think I can do much more with tis calculator and should move on to something else soon.
PMEmail Poster
Top
Unspecified
Lightning
Posted: Sep 24 2009, 07:43 PM
Quote Post


Ignorance isn't stupidity but choosing to remain ignorant is
[*][*]

Group Icon
Group: IRC Operators
Posts: 6381
Member No.: 583
Joined: 31-August 04

Status: (0d) [--]


yeah, you clearly understand flow control, basic arithmetic operations and input/output. go to the next concept now, and make something out of it too.

my recommendation: you've apparently got random down too, so when you get to arrays, see if you can figure out how to shuffle a deck of 52 cards and deal them out.

(oh, if you haven't already, figure out how to swap variables)


--------------------
click here to change my avatar. / gosh why are you even here lightning
hacker, n.an individual who enjoys learning computer system details and how to capitalize on his or her capabilities...not a criminal.
(from webster's new world hacker dictionary)
fedora linux 10
Fedora 10 Final!

Download today!
quality web comics (stories):
  1. girl genius: adventure! romance! mad science!
  2. punch an' pie: try a slice of life, then swallow.
  3. dresden codak: most interesting comic ever
quality web comics (one-shots):
  1. a softer world: truth and beauty bombs
  2. smbc: saturday morning breakfast cereal
  3. buttersafe: pictures and probably some words
"Religion is comparable to a childhood neurosis." - Sigmund Freud
“It is not by delusion, however exalted, that mankind can prosper, but only by unswerving courage in the pursuit of truth.” - Bertrand Russell
“To kill an error is as good a service as, and sometimes better than, the establishing of a new truth or fact.” - Charles Darwin
PMUsers WebsiteMSN
Top
United States
Xgoff
Posted: Sep 24 2009, 07:45 PM
Quote Post


<):|
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03

Status: (0d) [--]


QUOTE (Bacteriophage @ Sep 24 2009, 06:04 PM)
also if you're going to use decimal numbers I personally suggest double. There's still inaccuracy but there's less of it.

also floats don't support the full integer range that ints do (precision-wise); if you convert a float to an int you could potentially lose information

doubles not only have the full range but also an extra ~20 bits worth (if your ints are represented as 32-bits anyway), but of course are twice the size

QUOTE
int can do a lot of things that float can't. For example, an int number can be used as a counting number and be incremented/decremented as part of a for loop.

i'm pretty sure floats and doubles can be used for this is well, but yeah precision conflicts will likely bite you if you try


--------------------

This post may contain original research or unverified claims.
Please disregard the above information and contact an administrator.

DISCLAIMER: by sending me (xgoff) a private message, you agree to the directives and their terms specified henceforth:
DIRECTIVE 1 (APPLE): i may or may not reply promptly or at all; and there are no guarantees to the usefulness of the reply. i may not acknowledge whether i have even received your private message
DIRECTIVE 2 (CHILE CON CARNE): as per my view, "private" applies only to the initial transaction, and the material of your message may or may not be made public at my discretion; as this will more than likely be a post in the CCC or IRC, you may not be able to view it
DIRECTIVE 3 (FEATHER DUSTER): you must address me (xgoff) as "Sir Master Xgofficus his Highest and Most Awesome the Third"; failure to comply with this term may invoke one or both of the above directives, and i will leave a burning bag of **** on your doorstep
DIRECTIVE 4 (BOOTSTRAP): if you have read this disclaimer, please private message me promptly, in compliance with the above terms, so i can ensure you are capable of following directions you idiot
this concludes the test of the emergency disclaimer system, your scheduled programming will now continue. satisfaction guaranteed, and 100% cash back available under certain circumstances; restrictions may or may not apply within your place of residence
NOTICE: these directives and their terms may change at any time, without notice; as a private message transaction to myself assumes an understanding and full compliance of the above, you should ensure you are fully aware of the above terms at any point before sending a private message; any message received is assumed to have been sent in compliance with the above

QUOTE
(5:25:58 PM) Mikau: xgoff
(5:26:00 PM) Mikau: guess what
(5:26:04 PM) Xgoff: chicken butt
(5:26:09 PM) Mikau: **** you
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
Giygas
Posted: Sep 24 2009, 07:46 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


QUOTE (Lightning @ Sep 24 2009, 07:43 PM)
yeah, you clearly understand flow control, basic arithmetic operations and input/output.  go to the next concept now, and make something out of it too.

my recommendation: you've apparently got random down too, so when you get to arrays, see if you can figure out how to shuffle a deck of 52 cards and deal them out.

(oh, if you haven't already, figure out how to swap variables)

{Lightnings Seal of Approval}

Excellent, then- I guess my calculator is finished now ( Just added the function that clears the screen after you recieve your answer to avoid clutter ), so I guess I will be moving onto some slightly more advanced concepts.

More specificly, Control Structures and Functions.

Thanks for your support, guys- It really helps when other people know about it, or are learning to. :3.

This post has been edited by Giygas on Sep 24 2009, 07:47 PM
PMEmail Poster
Top
United States
Giygas
Posted: Sep 24 2009, 08:06 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


Looking through Structure, I realise that almost everything covered there was already present in my calculator, like if, else if, else, etc. And I am used to it.
However, Functions I have not used in my calculator, or even used extensively. Because I only have Functions to work with to expand, I am not sure what tool I can create that uses alot of functions with differen't formats.
Basiclly, a program that would show me how important functions can be in simple operations, and can get me used to using them, like the calculator did for input/output and commands.
PMEmail Poster
Top
United States
RetroXYZ
Posted: Sep 24 2009, 09:10 PM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


Structures and classes are extremely similar; almost exactly the same. Essentially, they're variables that contain other variables. Structures contain only variables, while classes can also contain functions. However, you cannot make any non-variable code outside of functions. For example:

struct user
{
std::string username;
std::string password;
};

And to call each, you would just refer to user.username and user.password. However, you cannot define these variables from within a function. Classes are a little different. You have to prefix definitions of functions and variables with public: or private: depending on whether or not the function/variable will be used only by the class or by other functions

For example
class user
{
public: std::string username;
private: std::string password;

public: bool confirm_login()
{
if (username=="User" && password=="Password")
{
return true;
}
else
{
return false;
}
}
};[/code]

Essentially, calling "user.username" is allowed, but "user.password" will return an error. You can call user.confirm_login() to check the login. It's simple once you get used to it, and object-oriented (structures and classes) programming is extremely useful in many cases.
PMEmail PosterMSN
Top
United States
Retriever II
Posted: Sep 25 2009, 01:01 AM
Quote Post


Catalyst
[H][*][*][*][*]
[*][*][*][*][*]


Group Icon
Group: Members
Posts: 18290
Member No.: 52
Joined: 13-October 03

Status: (0d) [--]


There is no difference between a struct and a class in C++, except that all members and inheritance defaults to private for a class, and public for a struct. Go ahead and define all the member functions you want in a struct, not that you generally have a reason to.

QUOTE (C++ FAQ Lite)
The members and base classes of a struct are public by default, while in class, they default to private. Note: you should make your base classes explicitly public, private, or protected, rather than relying on the defaults.

struct and class are otherwise functionally equivalent.

OK, enough of that squeaky clean techno talk. Emotionally, most developers make a strong distinction between a class and a struct. A struct simply feels like an open pile of bits with very little in the way of encapsulation or functionality. A class feels like a living and responsible member of society with intelligent services, a strong encapsulation barrier, and a well defined interface. Since that's the connotation most people already have, you should probably use the struct keyword if you have a class that has very few methods and has public data (such things do exist in well designed systems!), but otherwise you should probably use the class keyword.


--------------------

PMEmail PosterUsers WebsiteICQAOLMSN
Top
United States
Giygas
Posted: Sep 25 2009, 10:28 AM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


QUOTE
There is no difference between a struct and a class in C++, except that all members and inheritance defaults to private for a class, and public for a struct.

Oh! I think I get it now- I thought classes ere just a fancy way of introducing functions- but I think I get it now :3
Using classes and functions, i'll probrably see if I can, again, make a simple calculator. I think that's the best way of getting used to using them.
PMEmail Poster
Top
United States
Giygas
Posted: Sep 25 2009, 11:52 AM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


Arrays are very strange to work with!
As annoying as it is to have to define each number in an array, they seem to be very useful is many situations.

Like Lightning suggested, I am going to use Arrays to shuffle and deal 5 cards from a deck.
How I will make sure no two cards are repeated... I do not know, but I guess that's what I am doing this for :D
PMEmail Poster
Top
United States
Xgoff
Posted: Sep 25 2009, 11:58 AM
Quote Post


<):|
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03

Status: (0d) [--]


QUOTE (Giygas @ Sep 25 2009, 10:52 AM)
As annoying as it is to have to define each number in an array,

you don't always have to do this

the card sequences in particular can be generated through a loop, all you really have to do is tell C++ how large the array needs to be (this depends on if you're using a single array for every card, four separate arrays, or whatever


--------------------

This post may contain original research or unverified claims.
Please disregard the above information and contact an administrator.

DISCLAIMER: by sending me (xgoff) a private message, you agree to the directives and their terms specified henceforth:
DIRECTIVE 1 (APPLE): i may or may not reply promptly or at all; and there are no guarantees to the usefulness of the reply. i may not acknowledge whether i have even received your private message
DIRECTIVE 2 (CHILE CON CARNE): as per my view, "private" applies only to the initial transaction, and the material of your message may or may not be made public at my discretion; as this will more than likely be a post in the CCC or IRC, you may not be able to view it
DIRECTIVE 3 (FEATHER DUSTER): you must address me (xgoff) as "Sir Master Xgofficus his Highest and Most Awesome the Third"; failure to comply with this term may invoke one or both of the above directives, and i will leave a burning bag of **** on your doorstep
DIRECTIVE 4 (BOOTSTRAP): if you have read this disclaimer, please private message me promptly, in compliance with the above terms, so i can ensure you are capable of following directions you idiot
this concludes the test of the emergency disclaimer system, your scheduled programming will now continue. satisfaction guaranteed, and 100% cash back available under certain circumstances; restrictions may or may not apply within your place of residence
NOTICE: these directives and their terms may change at any time, without notice; as a private message transaction to myself assumes an understanding and full compliance of the above, you should ensure you are fully aware of the above terms at any point before sending a private message; any message received is assumed to have been sent in compliance with the above

QUOTE
(5:25:58 PM) Mikau: xgoff
(5:26:00 PM) Mikau: guess what
(5:26:04 PM) Xgoff: chicken butt
(5:26:09 PM) Mikau: **** you
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
Giygas
Posted: Sep 25 2009, 12:06 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


QUOTE (Xgoff @ Sep 25 2009, 11:58 AM)
you don't always have to do this

the card sequences in particular can be generated through a loop, all you really have to do is tell C++ how large the array needs to be (this depends on if you're using a single array for every card, four separate arrays, or whatever

Oh?
So using a loop, I could do,

card[4][52];

Without having to name each variable?
PMEmail Poster
Top
Unspecified
Lightning
Posted: Sep 25 2009, 12:19 PM
Quote Post


Ignorance isn't stupidity but choosing to remain ignorant is
[*][*]

Group Icon
Group: IRC Operators
Posts: 6381
Member No.: 583
Joined: 31-August 04

Status: (0d) [--]


QUOTE (Giygas @ Sep 25 2009, 01:06 PM)
Oh?
So using a loop, I could do,

card[4][52];

Without having to name each variable?

int deck[52];

should suffice.

then fill it up with unique values
and then shuffle it.

that's how to avoid duplicates

thinking about how to "shuffle" is an exercise that should get you thinking a little like a programmer

This post has been edited by Lightning on Sep 25 2009, 12:20 PM


--------------------
click here to change my avatar. / gosh why are you even here lightning
hacker, n.an individual who enjoys learning computer system details and how to capitalize on his or her capabilities...not a criminal.
(from webster's new world hacker dictionary)
fedora linux 10
Fedora 10 Final!

Download today!
quality web comics (stories):
  1. girl genius: adventure! romance! mad science!
  2. punch an' pie: try a slice of life, then swallow.
  3. dresden codak: most interesting comic ever
quality web comics (one-shots):
  1. a softer world: truth and beauty bombs
  2. smbc: saturday morning breakfast cereal
  3. buttersafe: pictures and probably some words
"Religion is comparable to a childhood neurosis." - Sigmund Freud
“It is not by delusion, however exalted, that mankind can prosper, but only by unswerving courage in the pursuit of truth.” - Bertrand Russell
“To kill an error is as good a service as, and sometimes better than, the establishing of a new truth or fact.” - Charles Darwin
PMUsers WebsiteMSN
Top
United States
Giygas
Posted: Sep 25 2009, 12:21 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


QUOTE (Lightning @ Sep 25 2009, 12:19 PM)
int deck[52];

should suffice.

then fill it up with unique values
and then shuffle it.

that's how to avoid duplicates

thinking about how to "shuffle" is an exercise that should get you thinking a little like a programmer

Oh alright, thank yo Lightning.

I guess I have to think for myself here, which isn't really a bad thing.
As long as I get the cards shuffled without duplicates, i'll be happy!
PMEmail Poster
Top
Unspecified
Lightning
Posted: Sep 25 2009, 12:22 PM
Quote Post


Ignorance isn't stupidity but choosing to remain ignorant is
[*][*]

Group Icon
Group: IRC Operators
Posts: 6381
Member No.: 583
Joined: 31-August 04

Status: (0d) [--]


do you know how to swap variables?


--------------------
click here to change my avatar. / gosh why are you even here lightning
hacker, n.an individual who enjoys learning computer system details and how to capitalize on his or her capabilities...not a criminal.
(from webster's new world hacker dictionary)
fedora linux 10
Fedora 10 Final!

Download today!
quality web comics (stories):
  1. girl genius: adventure! romance! mad science!
  2. punch an' pie: try a slice of life, then swallow.
  3. dresden codak: most interesting comic ever
quality web comics (one-shots):
  1. a softer world: truth and beauty bombs
  2. smbc: saturday morning breakfast cereal
  3. buttersafe: pictures and probably some words
"Religion is comparable to a childhood neurosis." - Sigmund Freud
“It is not by delusion, however exalted, that mankind can prosper, but only by unswerving courage in the pursuit of truth.” - Bertrand Russell
“To kill an error is as good a service as, and sometimes better than, the establishing of a new truth or fact.” - Charles Darwin
PMUsers WebsiteMSN
Top
United States
Giygas
Posted: Sep 25 2009, 12:23 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


QUOTE (Lightning @ Sep 25 2009, 12:22 PM)
do you know how to swap variables?

I understand what it means, but I not how to use it, really.
Would that make life alot easier?

edit: It makes use of pointers, right? I want to make sure I have the basic idea of them before using them!

This post has been edited by Giygas on Sep 25 2009, 12:25 PM
PMEmail Poster
Top
Unspecified
Lightning
Posted: Sep 25 2009, 12:55 PM
Quote Post


Ignorance isn't stupidity but choosing to remain ignorant is
[*][*]

Group Icon
Group: IRC Operators
Posts: 6381
Member No.: 583
Joined: 31-August 04

Status: (0d) [--]


no pointers yet.

int a = 5; int b = 8;

swap their values so that a ends up with 8 and b ends up with 5. that's a prerequisite for "shuffling"

This post has been edited by Lightning on Sep 25 2009, 12:55 PM


--------------------
click here to change my avatar. / gosh why are you even here lightning
hacker, n.an individual who enjoys learning computer system details and how to capitalize on his or her capabilities...not a criminal.
(from webster's new world hacker dictionary)
fedora linux 10
Fedora 10 Final!

Download today!
quality web comics (stories):
  1. girl genius: adventure! romance! mad science!
  2. punch an' pie: try a slice of life, then swallow.
  3. dresden codak: most interesting comic ever
quality web comics (one-shots):
  1. a softer world: truth and beauty bombs
  2. smbc: saturday morning breakfast cereal
  3. buttersafe: pictures and probably some words
"Religion is comparable to a childhood neurosis." - Sigmund Freud
“It is not by delusion, however exalted, that mankind can prosper, but only by unswerving courage in the pursuit of truth.” - Bertrand Russell
“To kill an error is as good a service as, and sometimes better than, the establishing of a new truth or fact.” - Charles Darwin
PMUsers WebsiteMSN
Top
United States
Giygas
Posted: Sep 25 2009, 01:02 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


QUOTE (Lightning @ Sep 25 2009, 12:55 PM)
no pointers yet.

int a = 5;  int b = 8;

swap their values so that a ends up with 8 and b ends up with 5.  that's a prerequisite for "shuffling"

Hmm...
Looks like i'm going to be doing some trial and error

But first,

user posted image

This will be the base part for when I get the shuffle working.
Whee~
PMEmail Poster
Top
United States
Giygas
Posted: Sep 25 2009, 01:23 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


QUOTE

#include <iostream>
#include <algorithm>
#include <ctime>
#include <cstdlib>
using namespace std;

int random(int r)
{
return rand()%r;
}

int main()
{
        std::srand(std::time(0));
        int numbers[5] = {1,2,3,4,5};
        std::random_shuffle(numbers, numbers + 5, random);
        for(int i=0; i<5; ++i)
        {
          std::cout << numbers[i] <<" ";
          }
         system("pause");
        return 0;
}

Can I have my cookie now :D?

This post has been edited by Giygas on Sep 25 2009, 01:24 PM
PMEmail Poster
Top
Unspecified
Lightning
Posted: Sep 25 2009, 01:30 PM
Quote Post


Ignorance isn't stupidity but choosing to remain ignorant is
[*][*]

Group Icon
Group: IRC Operators
Posts: 6381
Member No.: 583
Joined: 31-August 04

Status: (0d) [--]


...or you could just use the standard library one, I guess. the point was for you to write it yourself =P


--------------------
click here to change my avatar. / gosh why are you even here lightning
hacker, n.an individual who enjoys learning computer system details and how to capitalize on his or her capabilities...not a criminal.
(from webster's new world hacker dictionary)
fedora linux 10
Fedora 10 Final!

Download today!
quality web comics (stories):
  1. girl genius: adventure! romance! mad science!
  2. punch an' pie: try a slice of life, then swallow.
  3. dresden codak: most interesting comic ever
quality web comics (one-shots):
  1. a softer world: truth and beauty bombs
  2. smbc: saturday morning breakfast cereal
  3. buttersafe: pictures and probably some words
"Religion is comparable to a childhood neurosis." - Sigmund Freud
“It is not by delusion, however exalted, that mankind can prosper, but only by unswerving courage in the pursuit of truth.” - Bertrand Russell
“To kill an error is as good a service as, and sometimes better than, the establishing of a new truth or fact.” - Charles Darwin
PMUsers WebsiteMSN
Top
United States
Giygas
Posted: Sep 25 2009, 01:32 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


QUOTE (Lightning @ Sep 25 2009, 01:30 PM)
...or you could just use the standard library one, I guess.  the point was for you to write it yourself  =P

GOD FFFFFFFFFFF

Back to square one then :C
But I think I can do it now that I understand the basic idea, so maybe it won't be as bad as I think :3

This post has been edited by Giygas on Sep 25 2009, 01:33 PM
PMEmail Poster
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Pages: (10) 1 2 [3] 4 5 ... Last » Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.1263 ]   [ 13 queries used ]   [ GZIP Enabled ]   [ Server Load: 1.27 ]