switch statement problems..
Aug 25, 2008 at 5:52pm UTC
ok so here's my code:
Bookstore.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#ifndef BOOKSTORE_H
#define BOOKSTORE_H
#include <string>
#include <iostream>
using namespace std;
class Bookstore
{
private :
int iPrice;
int iPurchNum;
int iTotal;
public :
Bookstore( void );
~Bookstore();
void SetPurchaseNum( int iPurchNum );
int GetPurchaseNum( );
void SetPrice( int iPrice );
int GetPrice( );
};
#endif;
FictionBook.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef FICTIONBOOK_H
#define FICTIONBOOK_H
#include <string>
using namespace std;
#include "Bookstore.h"
class FictionBook:public Bookstore
{
private :
public :
void SetBookName( string & n );
string GetBookName();
};
#endif;
NonFictionBook.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef NONFICTIONBOOK_H
#define NONFICTIONBOOK_H
#include <string>
using namespace std;
#include "Bookstore.h"
class NonFictionBook:public Bookstore
{
private :
public :
void SetBookName( string & n );
string GetBookName();
};
#endif;
magazine.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef MAGAZINE_H
#define MAGAZINE_H
#include <string>
using namespace std;
#include "Bookstore.h"
class Magazine:public Bookstore
{
private :
public :
void SetMagazineName( string & n );
string GetmagazineName();
};
#endif;
includes.h
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef INCLUDES_H
#define INCLUDES_H
#include <iostream>
#include <string>
using namespace std;
#include "Bookstore.h"
#include "FictionBook.h"
#include "Magazine.h"
#include "NonFictionBook.h"
#endif;
source files...
Main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#include "Includes.h"
void main ( void );
void main()
{
string sName;
int iChoice;
cout << "Please enter your name: \n" ;
cin >> sName;
cout << endl << "Hello, " << sName << ", and welcome to Land'o'Books!\n\n" ;
cout << "What would you like to purchase today?\n\n" ;
cout << "\t 1. Fiction Book\n \t 2. NonFiction Book\n \t 3. Magazine\n\n" ;
cin >> iChoice;
switch ( iChoice )
case 1:
FictionBook oFictionBook = new FictionBook;
FictionBook->SetBookName(int );
FictionBook->GetBookName();
Bookstore->SetPurchNum(int );
Bookstore->GetPurchNum();
Bookstore->SetPrice(int );
Bookstore->GetPrice();
break ;
}
Bookstore.cpp
1 2 3 4 5 6 7 8 9
#include "Includes.h"
Bookstore::Bookstore()
{
cout << "Constructor firing off...\n" ;
}
and all I have in the other source files (FictionBook.cpp, NonFictionBook.cpp, Magazine.cpp) is the #include "Includes.h"
so here are my errors
--------------------Configuration: Schuth Tyler Final - Win32 Debug--------------------
Compiling...
Main.cpp
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(25) : error C2440: 'initializing' : cannot convert from 'class FictionBook *' to 'class FictionBook'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(27) : error C2143: syntax error : missing ';' before '->'
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(27) : error C2143: syntax error : missing ';' before '->'
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(28) : error C2143: syntax error : missing ';' before '->'
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(28) : error C2143: syntax error : missing ';' before '->'
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(30) : error C2143: syntax error : missing ';' before '->'
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(30) : error C2143: syntax error : missing ';' before '->'
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(31) : error C2143: syntax error : missing ';' before '->'
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(31) : error C2143: syntax error : missing ';' before '->'
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(33) : error C2143: syntax error : missing ';' before '->'
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(33) : error C2143: syntax error : missing ';' before '->'
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(34) : error C2143: syntax error : missing ';' before '->'
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(34) : error C2143: syntax error : missing ';' before '->'
C:\Documents and Settings\Administrator\Desktop\Schuth Tyler Final\Main.cpp(35) : error C2043: illegal break
Error executing cl.exe.
Schuth Tyler Final.exe - 14 error(s), 0 warning(s)
I'm not sure what I'm doing wrong, and when I go to correct it I get more errors. If I take my switch statement out I have no errors.
EDIT: I changed one line of code and fixed most of the errors. the line of code I changed is:
FictionBook *oFictionBook = new FictionBook
I put the * in front of the oFictionBook and it got rid of that problem. Now it tells me that I need to have a semicolon before my arrow ( -> ) operator when I'm declaring my functions and I'm not understanding that...
Last edited on Aug 25, 2008 at 6:01pm UTC
Aug 25, 2008 at 9:20pm UTC
FictionBook->SetBookName(int );
and the other set function calls aren't valid.. you need to specify the actual variable that you are sending, not the type. Also some of those dont even take ints, but strings.
Topic archived. No new replies allowed.