Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ Constructive Criticism
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Scathe
I post too much
Reputation: 0

Joined: 02 Aug 2006
Posts: 3631
Location: Smoking a blunt

PostPosted: Thu May 21, 2009 9:51 pm    Post subject: C++ Constructive Criticism Reply with quote

Im creating a program to manage my budget, i started it yesterday so its in the early stages, I have a few things i need to figure out so i figure why not post here?

Main things i need help with:
-Storing/Reading the last cursor position in a text file which contains all the information(e.g: I want to have all previous records saved, and update it weekly based on the most recent.)
-creating arrays of doubles...yes somehow im having trouble with that...
-creating classes for each type of function(e.g: Class for reading/writing to the file, a class for calculating..etc) Im not very good with classes i never understood how inheritance works...i try..but nope.

Anyways heres what i have so far. Any help would be appreciated



Code:
//Budget Calculator V0.03
//-Main Functions:
        //-Output to user
        //-Storing data in readable files
        //-Easily updatable(New Expenses/Pay changes)
       
       
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
   
    //Basic variable declarations
    string s_header_1="\t\tBudget Calculator v0.03\t\tLast updated May 20tth, 2009\n\n",
           s_instructions="\tUpdate:1 | Edit:2 |\n",
           s_dividerH="\t=========================================\n",
           s_layout="\n\tBalance  Checking  Savings  Expenses\n",
           s_dividerV="  |",
           s_week="Week ",
           s_update="Please enter the current date(MM/DD/YYYY)",
           s_update2="Please enter your current weeks information: ",
           s_updExpenses="New Expenses: ",
           s_updPaycheck="Current Paycheck: ",
           s_spendings="Enter each amount: ",
           s_line;
           
    bool updt=false, edit=false;
    char fin_update=' ';
           
    double d_balance,
        d_expenses_monthly,
        d_savings_total,
        d_paycheck,
        d_expenses_weekly,
        d_cur_savings;
   
    double d_additives[25];
       
    int month,
        day,
        year,
        f_choice,
        count=0,
        i_num_purchase;
       
    //print out header   
    cout<<s_header_1;
    cout<<s_instructions;
    cin>>f_choice;
    if(f_choice==1)
                   updt=true;
    else
        edit=true;
       
    while(updt){
               
                cout<<"How many purchases were made by card: ";
                cin>>i_num_purchase;
                for(int x=0;x<i_num_purchase;x++)
                {
                        cout<<s_spendings<<endl;
                        cin>>d_additives[x];
                        if(x==i_num_purchase){
                                              for(int y=0;y<i_num_purchase;y++){
                                               d_additives[0]=d_additives[y]+d_additives[y+1];
                                               }
                        }
                }
                cout<<"The total is "<<d_additives[0];
                //Write information to file
                //
    ofstream budget_write("budget.txt");
     if(budget_write.is_open())
     {
         budget_write << "Balance: "<<d_balance<<endl;
         budget_write << "Expenses: "<<d_expenses_monthly<<endl;
         budget_write << "Paycheck: "<<d_paycheck<<endl;
         budget_write << "Savings: "<<d_savings_total<<endl;
       budget_write.close();
    }
    else
    cout<<"Unable to open file"<<endl;
   
    cout<<"\nDone updating? y/n";
    cin>>fin_update;
   
    if(fin_update='y')
    updt=false;
    //Print updated data to user
    //
    ifstream budget_read("budget.txt");
   
    if(budget_read.is_open())
    {
       while(!budget_read.eof())
       {                 
                         getline(budget_read,s_line);
                         cout<<s_line<<endl;
       }
    budget_read.close();
    }
    else
    cout<<"Unable to open file"<<endl;
}
   
    cin.get();
    cin.get();
    return(0);
}
             
           


If the code is un-interpretable let me know i'll clean it up.

_________________

<Moose> they will call me beard penis
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Thu May 21, 2009 10:28 pm    Post subject: Reply with quote

I like the /* comment */ better than the // comments.
Back to top
View user's profile Send private message
yoyonerd
Grandmaster Cheater
Reputation: 0

Joined: 26 Apr 2008
Posts: 699
Location: -->formerly yoyonerd<--

PostPosted: Thu May 21, 2009 10:29 pm    Post subject: Reply with quote

Uhh, I can't remember what file has it but instead of cin.get() twice use _getch().

I'm curious to hear the answers for your actual questions, I use C# mainly.

_________________
Back to top
View user's profile Send private message AIM Address
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu May 21, 2009 10:41 pm    Post subject: Reply with quote

If you don't get something, it's time to invest in a good book
Back to top
View user's profile Send private message
Scathe
I post too much
Reputation: 0

Joined: 02 Aug 2006
Posts: 3631
Location: Smoking a blunt

PostPosted: Thu May 21, 2009 10:43 pm    Post subject: Reply with quote

slovach wrote:
If you don't get something, it's time to invest in a good book

Ive been reading the "Complete guide to programming in C++" But im more of a visual learner, and ive also tried visual tutorials. I literally have to do it like 10 times over and over again to get it, or reread shit.

_________________

<Moose> they will call me beard penis
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Thu May 21, 2009 11:29 pm    Post subject: Reply with quote

It's all in practice and experience. A year from now, you'll be damned amazed at what you can do. I can tell you this from personal experience.

It's a great journey, but don't forget to spend time with friends too :]

Edit:

I suggest moving a lot of the code into a header file and placing them in functions so that it's easier to reuse.
Back to top
View user's profile Send private message
Scathe
I post too much
Reputation: 0

Joined: 02 Aug 2006
Posts: 3631
Location: Smoking a blunt

PostPosted: Fri May 22, 2009 12:17 am    Post subject: Reply with quote

nwongfeiying wrote:
It's all in practice and experience. A year from now, you'll be damned amazed at what you can do. I can tell you this from personal experience.

It's a great journey, but don't forget to spend time with friends too :]

Edit:

I suggest moving a lot of the code into a header file and placing them in functions so that it's easier to reuse.


How do i define a block of code, usually more than one line and it changes color indicating its no longer defined.

unless i do
#DEFINE - code
#DEFINE - code pt2
#DEFINE - code pt3
...etc?

_________________

<Moose> they will call me beard penis
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Monkeys
I post too much
Reputation: 29

Joined: 20 Jul 2006
Posts: 2411

PostPosted: Fri May 22, 2009 4:45 am    Post subject: Reply with quote

And this is something small: instead of cin.get() twice, use cin.clear(); cin.get();

The cin.clear() clears the leftover \n (from the preceding cin) out of the buffer.
cin.get() would do nearly the same, but isn't build for that ;p

_________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Back to top
View user's profile Send private message
kittonkicker
I post too much
Reputation: 1

Joined: 19 Apr 2006
Posts: 2171

PostPosted: Fri May 22, 2009 4:53 am    Post subject: Reply with quote

Classes in C++ are pretty simple.

Example usage:

Code:
CCalculator.h

class CCalculator {
public:
         double Calculate(double no1, double no2); //code this function elsewhere
         double GetStoredResult();
private:
         double StoredResult;
};


Code:
CCalculator.cpp

#include "CCalculator.h"

double CCalculator::Calculate(double no1, double no2) {
      this->StoredResult = no1+no2;
      return this->StoredResult;
}

double CCalculator::GetStoredResult() {
      return this->StoredResult;
}


This is obviously a VERY simply class that has two functions and one variable. The first function adds two variables together, stores the result and then returns it. The second returns the stored result.

The variable StoredResult is where the function Calculate stores the result for later retrieval. It's "private" meaning you can only access it from inside that class or an inherited class (I think you'd change it to "protected" though if you wanted to access in an inherited class... can't remember).

This has either helped or confused the hell outta you! Good luck.


Last edited by kittonkicker on Wed May 27, 2009 3:38 pm; edited 1 time in total
Back to top
View user's profile Send private message
Scathe
I post too much
Reputation: 0

Joined: 02 Aug 2006
Posts: 3631
Location: Smoking a blunt

PostPosted: Fri May 22, 2009 2:20 pm    Post subject: Reply with quote

kittonkicker wrote:
Classes in C++ are pretty simple.

Example usage:

Code:
CCalculator.h

class CCalculator {
public:
         double Calculate(double no1, double no2); //code this function elsewhere
         double GetStoredResult();
private:
         double StoredResult;
};

CCalculator.cpp

#include "CCalculator.h"

double CCalculator::Calculate(double no1, double no2) {
      this->StoredResult = no1+no2;
      return this->StoredResult;
}

double CCalculator::GetStoredResult() {
      return this->StoredResult;
}


This is obviously a VERY simply class that has two functions and one variable. The first function adds two variables together, stores the result and then returns it. The second returns the stored result.

The variable StoredResult is where the function Calculate stores the result for later retrieval. It's "private" meaning you can only access it from inside that class or an inherited class (I think you'd change it to "protected" though if you wanted to access in an inherited class... can't remember).

This has either helped or confused the hell outta you! Good luck.


Thanks kiki!

Thats all it took for me to get it lmao, i just need a re-wording sometimes.

Now one question, when i create the function used by a class, do i keep that in the source file...or write it in the class header but just keep it global?

Also,
Code:
double CCalculator :: Calculate

What exactly is the :: ?

Thanks everyone for your responses!

_________________

<Moose> they will call me beard penis
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
LolSalad
Grandmaster Cheater
Reputation: 1

Joined: 26 Aug 2007
Posts: 988
Location: Australia

PostPosted: Fri May 22, 2009 4:52 pm    Post subject: Reply with quote

:: is the scope operator. Class::member is accessing the public 'member' variable inside the class 'Class'. This is different to accessing 'member' on an instance of the class 'Class'; the scope operator is accessing 'member' on 'Class' as a class, not an object of that class type.
_________________
Back to top
View user's profile Send private message MSN Messenger
Scathe
I post too much
Reputation: 0

Joined: 02 Aug 2006
Posts: 3631
Location: Smoking a blunt

PostPosted: Sun May 24, 2009 8:37 pm    Post subject: Reply with quote

Wahoa wrote:
:: is the scope operator. Class::member is accessing the public 'member' variable inside the class 'Class'. This is different to accessing 'member' on an instance of the class 'Class'; the scope operator is accessing 'member' on 'Class' as a class, not an object of that class type.


I see thank you Smile

_________________

<Moose> they will call me beard penis
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
iostream
How do I cheat?
Reputation: 0

Joined: 06 Apr 2009
Posts: 9
Location: georgia

PostPosted: Wed May 27, 2009 12:29 am    Post subject: Reply with quote

Quote:
Now one question, when i create the function used by a class, do i keep that in the source file...or write it in the class header but just keep it global?


Kiki just basically put two "files" in one code block.
Basically in your header file you will instantiate your class and methods, and in the corresponding source files you'll write your methods. methods are just another name for functions.

im still learning but im pretty sure thats correct.

_________________
Don't wait up.
Back to top
View user's profile Send private message MSN Messenger
iTz SWAT
I post too much
Reputation: 1

Joined: 20 Dec 2007
Posts: 2227
Location: Me.Location;

PostPosted: Wed May 27, 2009 1:07 am    Post subject: Reply with quote

Whats the best C++ Book?
_________________
Back to top
View user's profile Send private message
iostream
How do I cheat?
Reputation: 0

Joined: 06 Apr 2009
Posts: 9
Location: georgia

PostPosted: Wed May 27, 2009 2:42 am    Post subject: Reply with quote

Quote:
Uhh, I can't remember what file has it but instead of cin.get() twice use _getch().

conio.h has it ( i missed your question earlier)


@OP
to be completely honest with you , you can learn more from the internet.

cplusplus dot com ( i cant post url's yet)
also for some really outstanding video tutorials i liked 3dbuzz dot com
for the 3dbuzz one you have to register an account to view the full video's but its a free registration.

_________________
Don't wait up.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites