Thread: My first cpp app

  1. #16
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Ok, quick question, on this line of code:

    Code:
    void inputTwoNumbers(float& x, float& y)
    Why are there & symbols? Same goes for the prototype line.

    Also, I assume you are passing the x and y by reference down to the inputTwoNumbers function. Otherwise how would the values of x and y in the add and subtract functions be getting set. Is that correct?

  2. #17
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Originally posted by Shiro
    > More ideas for small time projects like this are welcome as well.

    You could do something simple like implementing a datastructure to learn about how to use the language and its language elements and constructions.

    Also you should experiment a bit with classes to see what C++ and Java have common and what is different. For example see how abstract classes are implemented in C++ and how they differ from Java. And experiment a bit with inheritance.

    When I started programming in Java, with a background in C++, I found a lot of things were similar. However, some things were a bit different and it is good to find out what the impact of the differences are. C++ for example allows multiple inheritance by classes, for Java you can something like that using interfaces.
    Great advice. Thank you! I'm going to do some reading, maybe beef up my Calc a little more. Then I'll get into classes, inheritance, pointers, etc. I know Java quite well, so some of this is easy. I'm not looking forward to pointers though. I've always been told that is the worst.

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The newer is <cmath>.


    You might want to use
    using std::cin;
    using std::cout;

    if you use those very often. Sorta like the import statements in Java.

    Why are there & symbols? Same goes for the prototype line.

    Also, I assume you are passing the x and y by reference down to the inputTwoNumbers function.
    Those two questions kind of delete each other . The & is what makes the parameter a reference instead of a copy.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #19
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Originally posted by fuh
    CompiledMonkey,
    have you learned about classes yet? If so, or when you do, you can make the calculator object oriented.

    P.S.:I attached my first calculator here. Before you look at the source try adding a square root function. I didn't get to this, but you could also add powers. If you're stumped, you can use sqrt() or pwr() in math.h (or is the newer one cmath or math?)
    No, I haven't gotten to classes yet. Today was my first with C++. I'll download your Calc, but I want to try and add some stuff by myself first. Like you suggested. Thanks for your help!

  5. #20
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    Originally posted by CompiledMonkey
    Today was my first with C++.
    Pretty good for your first day
    More program ideas:
    -A little game
    -Learn about file i/o and make a program to write something (like a soccer schedule and email it)
    -Play any card games? I made a Yu-Gi-Oh LP calculator
    -Make a math program (gives you two random numbers then you multiply them and see how far you can go)
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  6. #21
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Originally posted by CornedBee
    Those two questions kind of delete each other . The & is what makes the parameter a reference instead of a copy.
    Perfect!

  7. #22
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Originally posted by fuh
    Pretty good for your first day
    More program ideas:
    -A little game
    -Learn about file i/o and make a program to write something (like a soccer schedule and email it)
    -Play any card games? I made a Yu-Gi-Oh LP calculator
    -Make a math program (gives you two random numbers then you multiply them and see how far you can go)
    The game sounds cool. I've always wanted to get into games. Maybe I could start with a console based app. I dunno.

    I'm certainly going to do some file IO. I've got to finish a homework assignment for my programming class (hopefully tomo), and then I'll go that next.

    I just want to thank everyone that helped in this thread. Everyone was very helpful. If you guys wanna share some code you wrote when you first started or some stories, please do!

  8. #23
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Here was my approach for pointers. It worked, somewhat. First, I read a book which had a chapter on them. Didn't get them. Then I read a different book. Sorta got them, but not really. Then I read The Ultimate Guide to C++ or some such book...all I remember was it was written by Ivor Horton and had a red cover. I understood them better. Then I read some other stuff, and understood them quite well. It seems that nobody can write a good enough thing on pointers, and it takes the combination of several books... Anyway, after that, I proceeded to not code much for several months because I was spending too much time with school. During that time, I managed to forget a lot of stuff with pointers. Yay. I get to learn them again. Oh well, shouldn't be hard by now.

    For programs, you could make tic-tac-toe (really basic, I'm going to write a tutorial tonight probably, check the game forum later for a link), followed by pong (you might want to do something else before you do that) If you need a pong tutorial... *shameless plug* http://confuted.0catch.com/tutorials/ball/ball.html That covers ball movement. Also, you could try writing a matrix class and/or a linked list class. Those will give you some experience with arrays and pointers.
    Away.

  9. #24
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    A question, why do I have to include stdafx.h? That file looks like this:

    Code:
    // stdafx.h : include file for standard system include files,
    // or project specific include files that are used frequently, but
    // are changed infrequently
    //
    
    #pragma once
    
    
    #include <iostream>
    #include <tchar.h>
    
    // TODO: reference additional headers your program requires here
    When I try and just include iostream and tchar in my Calc.cpp file, I get "fatal error C1010: unexpected end of file while looking for precompiled header directive".

  10. #25
    Registered User HaLCy0n's Avatar
    Join Date
    Mar 2003
    Posts
    77
    It probably has something to do with how VS handles projects. Try just creating an empty C++ project, and doing it that way. That should work, and you shouldn't need tchar.h. I don't even know what that is to be honest.

  11. #26
    Striderjg123
    Guest
    tchar.h is from the windows api. It's a type for portability between unicode and ansi.

  12. #27
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Why can't I just include those two headers and drop the other files?

  13. #28
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Because you told VC++ in the project options that you are using stdafx.h as the precompiled header. If you don't include it, VC++ gets confused.


    The solution is to make every project an empty project and adding files yourself.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  14. #29
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Yeah, using GCC or some other compiler, you wouldn't need stdafx.h, just iostream
    Away.

  15. #30
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Using other project settings you wouldn't need it in VC++ either.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. Replies: 2
    Last Post: 04-09-2006, 07:20 PM
  3. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  4. best program to start
    By gooddevil in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-28-2004, 05:56 PM
  5. pasword app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-07-2003, 10:28 AM