Member Avatar for trebor-pl

Hi, i'm not very good at OOP, basically just started it.

My program basically its like a system for a game shop, the main isn't fully done yet, however main isn't a problem. The other files must contain some kind of problem in them. Well enough of the talk, I'll show the code and hope someone from you, the proper programmers comparying to me.

The thing is that I keep getting this error and not knowing how to fix it.
\string.h:24, from game.cpp /string.h:24, from game.cpp
\stddef.h extraneous `int' ignored
\stddef.h long, short, signed or unsigned invalid for `size_t'
\Makefile.win [Build Error] [game.o] Error 1

main

#include <iostream>
#include <string.h>
#include "customer.h"
#include "staff.h"
#include "game.h"

using namespace std;

int main()
{
    int choice, age, age_rating, id, id2;
    int customer_count = 1, staff_count =  1, game_count = 1;
    char name[50], address[75], email[50], phone_number[50], gender[6], job_position[50];
    char title[50], 
    bool gender_male;
    double wage_rate, price, discount_percentage, discount_amount, deposit;
    
    CCustomer customer[5];
    CStaff staff[5];
    CGame game[5];
    
    for( ; ; )//loops to show the menu
    {
        cout <<"Plese choose one of the following options:"<< endl;
        cout <<"1. Add Customer"<<endl;
        cout <<"2. Add Staff member"<<endl;
        cout <<"3. Add Game"<<endl;
        cout <<"4. Customer buys Game"<<endl;
        cout <<"5. Customers puts a deposit"<<endl;
        cin  >> choice;
    
        switch(choice)//meenu 
        {
            case 1://add customer
                   cout <<"Add Customer"<<endl;
                   cout <<"Enter name:"<<endl;
                   strcpy(name, cinRep());//used function cin replacement, then copies what was entered to 
                   customer[customer_count].setName(name);
                   
                   cout << endl <<"Enter age:"<< endl;
                   strcpy(age, cinRep());
                   customer[customer_count].setAge(age);
                   
                   cout << endl <<"Enter address:" << endl;
                   strcpy(address, cinRep());
                   customer[customer_count].setAddress(address);
                   
                   cout << endl <<"Enter phone number:"<< endl;
                   strcpy(phone_number, cinRep());
                   customer[customer_count].setPhone_number(phone_number);
                   
                   cout << endl <<"Enter email:"<< endl;
                   strcpy(email, cinRep());
                   customer[customer_count].setEmail(email);
                   
                   cout << endl <<"Enter gender:"<< endl;
                   strcpy(gender, cinRep());
                   if(gender == "male")
                       gender_male = true;
                   
                   else
                       gender_male = false;
                   
                   customer[customer_count].setGender_male(gender_male);
                   
                   customer[customer_count].setCustomer_id(customer_count);
            break;
            case 2:
                   cout <<"Add Staff"<<endl;
                   cout <<"Enter name:"<<endl;
                   strcpy(name, cinRep());//used function cin replacement, then copies what was entered to 
                   staff[staff_count].setName(name);
                   
                   cout << endl <<"Enter age:"<< endl;
                   strcpy(age, cinRep());
                   staff[staff_count].setAge(age);
                   
                   cout << endl <<"Enter address:" << endl;
                   strcpy(address, cinRep());
                   staff[staff_count].setAddress(address);
                   
                   cout << endl <<"Enter phone number:"<< endl;
                   strcpy(phone_number, cinRep());
                   staff[staff_count].setPhone_number(phone_number);
                   
                   cout << endl <<"Enter email:"<< endl;
                   strcpy(email, cinRep());
                   staff[staff_count].setEmail(email);
                   
                   cout << endl <<"Enter gender:"<< endl;
                   strcpy(gender, cinRep());
                   if(gender == "male")
                       gender_male = true;
                   
                   else
                       gender_male = false;
                   
                   staff[staff_count].setGender_male(gender_male);
                   
                   cout << endl <<"Enter Job position:"<< endl;
                   strcpy(job_position, cinRep());
                   staff[staff_count].setJob_position(job_position);
                   
                   cout << endl <<"Enter Wage rate:"<< endl;
                   strcpy(wage_rate, cinRep());
                   staff[staff_count].setWage_rate(wage_rate);
                   
                   staff[staff_count].setStaff_id(staff_count);
            break;
            case 3:
                   cout <<"Add Game"<<endl;
                   cout <<"Enter Title:"<<endl;
                   strcpy(title, cinRep());//used function cin replacement, then copies what was entered to 
                   game[game_count].setTitle(title);
                   
                   cout << endl <<"Enter age rating:"<< endl;
                   strcpy(age_rating, cinRep());
                   game[game_count].setAge(age_rating);
                   
                   cout << endl <<"Set price:" << endl;
                   strcpy(price, cinRep());
                   game[game_count].setPrice(price);
                   
                   game[game_count].setGame_id(game_count)
            break;
            case 4:
                   cout <<"Buy a game"<<endl;
                   cout <<"Get game by ID"<< endl;
                   strcpy(id, cinRep());
                   
                   cout <<"Enter Customer ID"<<endl;
                   strcpy(id2, cinRep());
                   
                   cout <<"You are buying this game "<<game[id].getTitle()<<" for £"<<game[id].getPrice()<<"."<<endl;
                   
                   customer[id2].buy_game();               
            break;
            case 5:
                   cout <<"Enter Customer ID"<<endl;
                   strcpy(id2, cinRep());
                   cout <<"What is the amount to be deposited?"<<endl;
                   srtcpy(deposit, cinRep());
                   customer[id2].add_balance(deposit);
                 
            break;
            default: 
                     cout <<"Incorrect choice"<<endl;
            break;
            
        }
    }
        
    
    return 0;   
}

char* cinRep()
{
    char sentence[150], ch;
    int count = 0;
    
    /*
      if cout is used with getche and no endl is used then add this line after cout
      cout.flush();
    */    
    do
    {
        ch = getche();
        sentence[count] = ch;
        count ++;
    }while(ch != '\r');
    
    sentence[count-1] = '\0';
    
    return sentence;
}

customer.h

#ifndef CUSTOMER_H
#define CUSTOMER_H
#include "game.h"
#include "person.h"

class CCustomer : public CPerson // Class for Customer that inherits from CPerson
{
      private:
              int customer_id;
              double balance;
              double deposit;
              double withdraw;
              CGame game[1000];
              int gamecount;
              
      public:
             //------------------------constructors-----------------------------
             CCustomer();
             CCustomer(char theName[], bool theGender_male, int theAge, char theAddress[], char thePhone_number[], char theEmail[], double theBalance);
             
             int getCustomer_id()                             {return customer_id;};
             void setCustomer_id(int theCustomer_id);   
             
             double getBalance()                                { return balance;};
             void setBalance(double theBalance);     
             
             void add_balance(double theDeposit);
             void subtract_balance(double theWithdraw);
             
             void buy_game();
};

#endif

customer.cpp

//Methods Module
#include "customer.h"
#include <string.h>


CCustomer::CCustomer(char theName[], bool theGender_male, int theAge, char theAddress[], char thePhone_number[], char theEmail[], double theBalance)
{
    strcpy(name, theName);
    gender_male = theGender_male;
    age = theAge;
    strcpy(address, theAddress);
    strcpy(phone_number, thePhone_number);
    strcpy(email, theEmail); 
    balance = theBalance;
}

void CCustomer::setCustomer_id(int theCustomer_id)
{
    customer_id = theCustomer_id;
}

void CCustomer::setBalance(double theBalance)
{
    balance = theBalance;
}

void CCustomer::add_balance(double theDeposit)
{
    balance += theDeposit;
}

void CCustomer::subtract_balance(double theWithdraw)
{
    balance -= theWithdraw;
}

void CCustomer::buy_game()
{
    gamecount++;
    balance = game[game_id].getPrice() - balance;
    return balance;
}

game.h

#ifndef GAME_H
#define GAME_H
class CGame // Class for game
{
      private:
              int game_id;
              char title[25];
              double price;
              int age_rating;
              double discount_percentage;
              double discount_amount;
              
      public:
             //---------------------------constructors--------------------------
             CGame();
             CGame(int theGame_id, char theTitle[], double thePrice, int theAge_rating);
             
             int getGame_id()                                 {return game_id;};
             void setGame_id(int theGame_id);
             
             char* getTitle()                                   {return title;};
             void setTitle(char theTitle[]);
             
             double getPrice()                                  {return price;};
             void setPrice(double thePrice);  
             
             int getAge_rating()                                {return age_rating;};
             void setAge_rating(int theAge_rating);  
             
             void Discount_percntg(double theDiscount_percentage);
             void Discount_amnt(double theDiscount_amount);
}
#endif

game.cpp

//Methods Module
#include "game.h"
#include <string.h>


CGame::CGame(int theGame_id, char theTitle[], double thePrice, int theAge_rating)
{
    game_id = theGame_id;
    strcpy(title, theTitle);
    price = thePrice;
    age_rating = theAge_rating;
}

void CGame::setGame_id(int theGame_id)
{
    game_id = theGame_id;
}

void CGame::setTitle(char theTitle[])
{
    strcpy(title, theTitle);
}

void CGame::setPrice(double thePrice)
{
    price = thePrice;
}

void CGame::setAge_rating(int theAge_rating)
{
    age_rating = theAge_rating;
}

void CGame::Discount_amnt(double theDiscount_amount)
{
    price -= theDiscount_amount;
}

void CGame::Discount_percntg(double theDiscount_percentage)
{
    price -= theDiscount_percentage;
}

I also have staff.h, staff.cpp, person.h and person.cpp. Classes in files customer.h and staff.h inherit from person.h ;)

Thanks for help and looking forward for replies

You seem to be missing a semicolon ..

class CGame 
{
   ...

} ; // <--- add semicolon
Member Avatar for trebor-pl

thaks very much mate ;)
this has helped me a lot, I know it was a schoolboy error but I don't know how I didn't see it.

That fixed my problems, then some new ones appeared, I fixed them. However got some linking errors now:

[Linker error] undefined reference to `CPerson::CPerson()'
[Linker error] undefined reference to `CPerson::CPerson()'
[Linker error] undefined reference to `CCustomer::CCustomer()'
[Linker error] undefined reference to `CStaff::CStaff()'
[Linker error] undefined reference to `CGame::CGame()'
[Linker error] undefined reference to `CPerson::CPerson()'
[Linker error] undefined reference to `CGame::CGame()'
[Linker error] undefined reference to `CPerson::CPerson()'
[Linker error] undefined reference to `CGame::CGame()'
ld returned 1 exit status
Makefile.win [Build Error] [OOP.exe] Error 1


Do you know the answer for that, have been trying to sort it in my own however I failed.

I would be really glad if you could help me with this aswell.

Linking errors means that the code you've written makes sense, but when the linker goes looking for some functions you have promised to provide (usually in a header file), it can't find them in a compiled form. These functions look like the default constructors for CPerson, CCustomer, CStaff and CGame.

Take a closer look at your class declarations. You have declared user-defined default constructors, but you haven't implemented them in your *.cpp files. You need to provide implementations.

Member Avatar for trebor-pl

thank you for guide ;) that worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.