C++ program help


 
Thread Tools Search this Thread
Top Forums Programming C++ program help
# 1  
Old 09-22-2011
C++ program help

this won't compile can you please help thx...

Header files:
Code:
********************************************
VideoItem class
************************************
#pragma once
#include <string>
using namespace std;

class VideoItem
{
public:
VideoItem(); //default constructor
~VideoItem(); //deconstructor
VideoItem (const VideoItem & vi);
VideoItem (string n, int c, int qStore, int qS, int qB, int qRO, int qFS, int qFR);

string ToString();
void FromString(string s);
static string HeaderString();

string getname();
int getCodeNum ();

int getStorequantity ();
void setStorequantity (int qStore);

int getForSalequantity ();
void setForSalequantity (int qFS);
int getForRentquantity ();
void setForRentquantity (int qFR);

void randomize();



private:
string name; // name of video
int CodeNum; //unique code of video
int Storequantity;//quantity store owned
int Soldquantity;//quantity sold
int Boughtquantity;//quantity bought
int RentedOutquantity;//quantity rented out
int ForSalequantity; //quantity for sale
int ForRentquantity;// quantity for rent

};

#include "VideoItem.h"
#include "misc.h"
#include <iostream>
using namespace std;

VideoItem::VideoItem()
{
name = " ";
CodeNum = 0;
Storequantity = 0;
Soldquantity = 0;
Boughtquantity = 0;//quantity bought
RentedOutquantity = 0;//quantity rented out
ForSalequantity = 0; //quantity for sale
ForRentquantity = 0;// quantity for rent
}

VideoItem::VideoItem (string n, int c, int qStore, int qS, int qB, int qRO, int qFS, int qFR)
{
name = n;
CodeNum = c;
Storequantity = qStore;
Soldquantity = qS;
Boughtquantity = qB;
RentedOutquantity = qRO;
ForSalequantity = qFS;
ForRentquantity = qFR;
}

void VideoItem::randomize()
{
name=randString(3);
CodeNum=randInt(1,999999999);
Storequantity=randInt(10,100000);
RentedOutquantity=randInt(0,10000);
Soldquantity=randInt(0,10000);
ForSalequantity=randInt(0,10000);
ForRentquantity=randInt(1,1000);
}

string VideoItem::ToString()
{
string result="";
result+=padRight(name,' ',15);
result+=padLeft(intToString(CodeNum),'0',10);
result+=padLeft(intToString(Storequantity),' ',8);
result+=padLeft(intToString(RentedOutquantity),' ',8);
result+=padLeft(intToString(Soldquantity),' ',6);
result+=padLeft(intToString(ForSalequantity),' ',6);
result+=padLeft(intToString(ForRentquantity),' ',6);
return result;
}

string VideoItem::HeaderString()
{
char fill='-';
string result="";
result+=padRight("Video Name",fill,15);
result+=padLeft("Code",fill,10);
result+=padLeft("In Store",fill,8);
result+=padLeft("Rented Out",fill,8);
result+=padLeft("Sold",fill,6);
result+=padLeft("For Sale",fill,6);
result+=padLeft("For Rent",fill,6);
return result;
}

VideoItem::~VideoItem()
{

}

*************************************************************
VideoStore class
****************************************************
#pragma once
#include "VideoItem.h"
using namespace std;

class VideoStore
{
public:
VideoStore();
~VideoStore();
void run ();
void listCommand();
void generateRandItems(int num);
void help();
void buy();
void rebuy();
void rent();
void sell();
void report();
void test();


private:
VideoItem inventory;

};

#include "VideoStore.h"
#include "misc.h"
#include <iostream>
using namespace std;

void VideoStore::run()
{
string command = "";
cout <<"Welcome to CW Video Store.\n"<<endl;
cout << "Please enter a command >";
cin>>command;

while((command!="QUIT")&&(command!="7"))
{

if ((command == "HELP")||(command == "0"))
listCommand();
else if ((command == "BUY")||(command =="1"))
buy();
else if ((command == "REBUY")||(command =="2"))
rebuy();
else if ((command == "RENT")||(command == "3"))
rent();
else if ((command == "SELL")||(command == "4"))
sell();
else if ((command == "REPORT")||(command == "5"))
report();
else if ((command == "TEST")||(command == "6"))
{
generateRandItems(10);
}


else if ((command == "Quit")||(command == "7"))
cout <<"Goodbye."<<endl;

else
cout << "** Not a valid command **" << endl;
cout << "Re-Enter a command: ";
cin >> command;
}
}


void VideoStore::listCommand()
{
cout <<"CW Video Store Commands"<<endl;
cout <<"**--------------------------------**"<<endl;
cout <<"0) HELP - list the commands"<<endl;
cout <<"7) QUIT - leave the store"<<endl;
cout <<"1) BUY - add new video to the inventory"<<endl;
cout <<"2) REBUY - add an existing video to the inventory"<<endl;
cout <<"3) RENT - rent a video"<<endl;
cout <<"4) SELL - sell a video"<<endl;
cout <<"5) REPORT - list of all videos"<<endl;
cout <<"6) TEST - generate 10 random videos"<<endl;


void VideoStore::buy()

{
string name;
int c;
int qB;
cout <<"Please enter the video's name: ";
cin >>name;

cout <<"Enter the code number: ";
cin >>c;

cout <<"Enter quantity being bought: ";
cin >>qB;

VideoItem newVideo(string n, int c, int qb);
inventory.push_back(newVideo);

cout <<"[video saved]" <<endl;
cout <<endl;
}

void VideoStore::rebuy()
{
int c;
int qB;

cout <<"Please enter the video's code number: "<<endl;
cin >>c;

cout <<"Enter quantity being bought: "<<endl;
cin >> qB;

refVi.setStorequantity (refVi.getStorequantity() + qB);
}


void VideoStore::rent()
{
int c;
int qFR;

cout <<"Please enter the video's code number: "<<endl;
cin >>c;

if (qStore!=0)
refVi.setquantityRentedOut (refVi.getquantityRentedOut() + 1);
else
{cout <<"There are no available videos"<<endl;}
}

void VideoStore::sell()
{
int c;
int qS;

cout <<"Please enter the video's code number: "<<endl;
cin >>c;

cout <<"Quantity being sold: "<<endl;
cin >>qS;

if (qStore!=0)
refVi.setStorequantity (refVi.getStorequantity()- 1);
else
{cout <<"There are no available videos"<<endl;}

}

void VideoStore::report()
{
cout<<VideoItem::HeaderString()<<endl;
for(unsigned int i=0;i<inventory.size();i++)
{
cout<< inventory.getItem(i).ToString()<<endl;
}
}

void VideoStore::generateRandItems(int num)
{
VideoItem vi;
for(int i=0;i<num;i++)
{
vi.randomize();
inventory.addNewVideo(vi);
//VideoItem.push_back(vi);
}
}

VideoStore::VideoStore()
{
inventory.clear();
}

VideoStore::~VideoStore()
{
inventory.clear();
}


int main()
{
VideoStore myStore;
myStore.run();

return 0;
}

Moderator's Comments:
Mod Comment Please use [CODE] tags when posting source listings. Here's a tutorial on how to do that

Last edited by pludi; 09-22-2011 at 11:54 AM..
# 2  
Old 09-22-2011
I can't sort out which parts are supposed to be which file. I'm pretty sure misc.h is missing, too. Post again please?

---------- Post updated at 09:12 AM ---------- Previous update was at 09:06 AM ----------

1) There's no closing brace for ::listcommand().
Code:
void VideoStore::listCommand()
{
cout <<"CW Video Store Commands"<<endl;
cout <<"**--------------------------------**"<<endl;
cout <<"0) HELP - list the commands"<<endl;
cout <<"7) QUIT - leave the store"<<endl;
cout <<"1) BUY - add new video to the inventory"<<endl;
cout <<"2) REBUY - add an existing video to the inventory"<<endl;
cout <<"3) RENT - rent a video"<<endl;
cout <<"4) SELL - sell a video"<<endl;
cout <<"5) REPORT - list of all videos"<<endl;
cout <<"6) TEST - generate 10 random videos"<<endl;
} // Missing

2) You're using #pragma once in your headers, when you should be doing

Code:
#ifndef __HEADER_FILE_NAME__
#define __HEADER_FILE_NAME__

class stuff
{
...
};

#endif/*__HEADER_FILE_NAME__*/

This is because #pragma once only works with very few compilers.

3) Instead of putting 'using namespace::std' in each and every one of your header files, just use std::string.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl program get a response before the program quits

I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade. I have: if ( $response =~ m/^/ ) { $user_wants_to_quit... (1 Reply)
Discussion started by: germany1517
1 Replies

2. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

3. Programming

Calling c program from another c program

Hi All, Probably this is a repeated question. My knowledge in this is limited and i got confused on all those materials i got in google search. We use #include <> to include a predefined library like stdio.h i saw somewhere that #include "" includes a man made module(another C program). IS... (2 Replies)
Discussion started by: jisha
2 Replies

4. Programming

Python program faster than C++ program.

I wrote a simple program that generates a random word 10,000,000 times. I wrote it in python, then in C++ and compared the two completion times. The python script was faster! Is that normal? Why would the python script be faster? I was under the impression that C++ was faster. What are some of... (2 Replies)
Discussion started by: cbreiny
2 Replies

5. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

6. Programming

A program to trace execution of another program

Hi, I wanted to know if i can write a program using switches and signals, etc to trace execution of other unix program which calls c program internally. If yes how? If not with signals and switches then are there any other methods apart from debugging with gdb/dbx. (3 Replies)
Discussion started by: jiten_hegde
3 Replies

7. UNIX for Dummies Questions & Answers

How to write to stdin of another program (program A -> [stdin]program B)

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question: ---------... (3 Replies)
Discussion started by: vvaidyan
3 Replies

8. Programming

How to write to stdin of another program (program A -> [stdin]program B)

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question: ---------... (1 Reply)
Discussion started by: vvaidyan
1 Replies

9. Programming

executing a program within a program

Read the title: how do i do it? (4 Replies)
Discussion started by: Gekko
4 Replies

10. Programming

Please need help with C program!

My program only ouputs the correct magic square sum totals for the number 15.If I enter any odd number smaller than 15 my sum totals are incorrect. I have define "size" to 15. How or what do I change so that my program will output the magic square results for the odd numbers 1 through 15 without... (1 Reply)
Discussion started by: JJJ
1 Replies
Login or Register to Ask a Question