guys my instructor gave me a project :

a file that contain 5 text files

2 for sale_item( header file, cpp file_

2 for sale file ( header file, cpp file

1 for main

-------------------------------------------------------------

to start u need 2:

1. create new project

2. call it the same name as main file (a3main)

3. change from gui to console

4. add 2 nodes sale file and sale item

5 delete the def node

6. run

then a black box shows that tells u error no1 and the probem

there are 16 errors.
--------------------------------------------------------------

thx for helping guys this is my first post im really desperate here

put these attached files into 1 folder

Attachments
/************************************************************
* a3main.cpp               Vrsion 1.2 by Fardad Soleimanloo *
*                                                           *
* Main program for COSC222 multi-projects.                  *
*                                                           *
* Compile this program with your salefile.cpp and           *
* saleitem.cpp files.
*                                                           *
* If this succeeds, then run a3main. It will tell you if    *
* projet is ready     or not.                               *
*                                                           *
************************************************************/
#include <conio.h>
#include <iostream.h>

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "saleitem.h"
#include "salefile.h"

struct sale_rec{
   char
      name[41],
      bar_code[11];
   int
      qntty;
   double
      uprice;
   sale_rec(char *n,char *b,int q,double u){
      strncpy(name,n,40);
      name[40]=0;
      strncpy(bar_code,b,10);
      bar_code[10] = 0;
      qntty = q;
      uprice = u;
   }
};
int operator==(const sale_item &s,const sale_rec &r);
int operator!=(const sale_item &s,const sale_rec &r);
void Err(const int num,const char *errmes);
void message(const char *str);
void pause(void);
int same(double a,double b);
void Debug(void);
void createfile(char *fname,int bad);

void main(void){
   int oksofar = 1;
   fprintf(stderr,"Checking sale_item class:\n");
   pause();

   if(sale_item() != sale_rec("","",0,0)){
      Err(1,"sale_item default constructor has problem...");
      oksofar = 0;
   }
   if(oksofar &&
      sale_item("name","1234567890",2.99) != sale_rec("name","1234567890",1,2.99)){
      Err(2,"sale_item(char *,char *, double) has problem...");
      oksofar = 0;
   }
   if(oksofar &&
      sale_item("1234567890",2) != sale_rec("","1234567890",2,0.0)){
      Err(3,"sale_item(char *, int) has problem...");
      oksofar = 0;
   }
   if(oksofar){
      sale_item
         s,
         s1("name 1","1234567890",100.0),
         s2("name 1","1234567890",200.0);
      s2.quantity(2);
      s = s1+s2;
      if(s == sale_rec("name 1","1234567890",3,500.0)){
         Debug();
         oksofar = 0;
      }
      else if( s != sale_rec("name 1","1234567890",3,166.66667)){
         Err(4,"The + operator is not working properly...");
         oksofar = 0;
      }
      s1 += s2;
      if(oksofar && s1 == sale_rec("name 1","1234567890",3,300.0)){
         Err(5,"use the add() function or the operator+ for implementing +=");
         oksofar = 0;
      }
      else if(oksofar &&  s1 != sale_rec("name 1","1234567890",3,166.66667)){
         Err(6,"The += operator is not working properly...");
         oksofar = 0;
      }
      if(oksofar && !(s1==s2)){
         Err(7,"The == operator is not working properly...");
         oksofar = 0;
      }
   }
   if(oksofar){
      message("Project III is done");
      message("Passed sale_item class test.\n\n");
      fprintf(stderr,"Checking infile class:\n");
      pause();
   }
   createfile("prclist.txt",0);
   createfile("pricelst.txt",1);
   infile
      *in = NULL;
   if(oksofar){
      in = new infile;
   }
   if(oksofar && in->fail()){
      Err(8,"Problem either in default constructor or fail() method...");
      oksofar = 0;
   }
   if(oksofar){
      delete in;
      in = new infile("pricelst.txt");
   }
   if(oksofar && in->fail()){
      Err(9,"Problem either in infile(char *) or fail() method...");
      oksofar = 0;
   }
   sale_item si;
   if(oksofar && !in->scan(si)){
      Err(10,"infile can not read properly...");
      oksofar = 0;
   }

   if(oksofar && si != sale_rec("name number 1", "1234567891", 0, 1.1)){
      Err(11,"infile can not read properly...");
      oksofar = 0;
   }

   if(oksofar){
      while(in->scan(si));
      in->scan(si);
      in->scan(si);
   }

   if(oksofar && in->count() != 5){
      Err(12,"Incorrect number of read records...");
      oksofar = 0;
   }


   if(oksofar && si != sale_rec("name number 5","1234567895",0,5.5)){
      Err(13,"Overwriting the value in sale_item even if the scan() is not successful");
      oksofar = 0;
   }

   if(oksofar && !in->fail()){
      Err(14,"infile must fail at the end of file or bad data");
   }

   if(oksofar){
      in->reset();
      for(int i = 0;i<3;i++){
         in->scan(si);
      }
   }


   if(oksofar && in->fail()){
      Err(15,"fail() does not work properly...");
      oksofar = 0;
   }

   if(oksofar && (in->count() != 3 ||
                 si != sale_rec("name number 3","1234567893",0,3.3))){
      Err(16,"reset() does not work properly...");
      oksofar = 0;
   }


   if(oksofar){
      message("Project IV\n");
      message("Passed infile class test.\n\n");
      fprintf(stderr,"Checking outfile class:\n");
      pause();
   }


   outfile  *out = NULL;
   if(oksofar){
      out = new outfile;
      delete in;
      in = new infile;
      while(in->scan(si));
   }
   if(oksofar && out->fail()){
      Err(17,"Either the fail() does not work or disk is write protected.");
      oksofar = 0;
   }

   if(oksofar && in->count() != 5){
      Err(18,"Problem in default constructor of outfile or count() in infile");
   }

   if(oksofar){
      in->reset();
      delete out;
      out = new outfile('X');
      in->scan(si);
   }

   if(oksofar && !in->fail()){
      Err(19,"outfile('X') does not work...");
      oksofar = 0;
   }
   if(oksofar){
      in->reset();
      in->scan(si);
      out->write(sale_item("new file item","1112223330",20.2));
      delete out;
   }
   if(oksofar && (!in->scan(si) ||
                  si != sale_rec("new file item","1112223330",0,20.2))){
      Err(20,"problem in write()...");
      oksofar = 0;
   }


   if(oksofar){
      createfile("prclist.txt",0);
      out = new outfile;
      delete in;
      in = new infile;
      si.set("name number 6","1234567896",6.6);
      out->write(si);
      out->flush();
      while(in->scan(si));
   }
/////////////////////////////////////////////////////////////////////////////
   if(oksofar && (in->count() != 6  ||
                  si != sale_rec("name number 6","1234567896",0,6.6))){
      Err(21,"flush() is not working properly...");
      oksofar = 0;
   }
/////////////////////////////////////////////////////////////////////////////
   if(oksofar){
      out->del_data();
      in->reset();
   }
   if(oksofar && in->scan(si)){
      Err(22,"del_data() is not deleting the data in the file...");
      oksofar = 0;
   }

   if(oksofar){
      delete in;
      delete out;
      createfile("hiihaa.txt",0);
      out = new outfile("hiihaa.txt");
      in = new infile("hiihaa.txt");
      out->write(sale_item("hiihaa hoohoo","9998887770",99.99));
      out->flush();
      while(in->scan(si));
   }

   if(oksofar && (in->count() != 6
                  || si != sale_rec("hiihaa hoohoo","9998887770",1,99.99))){
      Err(23,"outfile(char *) has problem...");
      oksofar = 0;
   }

   if(oksofar){
      delete out;
      out = new outfile("hiihaa.txt",'x');
      in->reset();
      while(in->scan(si));
   }

   if(oksofar && (in->count() != 6
                  || si != sale_rec("hiihaa hoohoo","9998887770",1,99.99))){
      Err(24,"outfile(char *,char) has problem...");
      oksofar = 0;
   }


   if(oksofar){
      delete out;
      out = new outfile("hiihaa.txt",'X');
      in->reset();
      in->scan(si);
   }

   if(oksofar && !in->fail()){
      Err(25,"outfile(char *,char) does not overwrite when called with 'X'...");
      oksofar = 0;
   }

   if(oksofar){
      int    i;
      delete out;
      createfile("hiihaa.txt",0);
      out = new outfile("hiihaa.txt");
      for(i=0;i<10;i++){
         out->write(si);
      }
      out->flush();
      for(i=0;i<10;i++){
         out->write(si);
      }
      out->flush();
      in->reset();
      while(in->scan(si));
   }

   if(oksofar && in->count() != out->count()+5){
      Err(26,"count() does not work properly...");
      oksofar = 0;
   }

   if(in)
      delete in;
   if(out)
      delete out;
   if(oksofar){
      message("Passed outfile class test.\n\n\n");
   }
   if(oksofar){
      message("Project V\n");
      message("Well done!");
   }
   else{
      message("Not ready yet, keep working on it. You can do it!");
   }
   pause();
}




int operator==(const sale_item &s,const sale_rec &r){
   char temp[41];
   int  res;
   s.getname(temp);
   res = !strcmp(temp,r.name);
   s.getcode(temp);
   res = res && !strcmp(temp,r.bar_code);
   return res && s.quantity() == r.qntty && same(s.unit_price(), r.uprice);
}
int operator!=(const sale_item &s,const sale_rec &r){
   return !(s==r);
}
void Err(const int num,const char *errmes){
   fprintf(stderr,"Error %d: %s\n",num,errmes);
}
void message(const char *str){
   fprintf(stdout,"%s\n",str);
}
void pause(void){
   fprintf(stderr,"Press <enter> to continue...");
   while(getchar() != '\n');
}
int same(double a,double b){
   return a-b> -0.0001 && a-b < 0.0001;
}
void Debug(void){
   fprintf(stderr,"There is a bug in function \"add()\" in file \"saleitem.cpp\" which should\n");
   fprintf(stderr,"be fixed before proceeding to the next step:\n");
   fprintf(stderr,"The else part of the if statement in \"add()\" function is:\n\n");

   fprintf(stderr,"else{\n");
   fprintf(stderr,"   s.set(s1.name,s1.bar_code,s1.price()+s2.price());\n");
   fprintf(stderr,"   s.quantity( s1.quantity() + s2.quantity());\n");
   fprintf(stderr,"}\n\n");

   fprintf(stderr,"Please change the else statement to:\n\n");

   fprintf(stderr,"else{\n");
   fprintf(stderr,"   int\n");
   fprintf(stderr,"      q1 = s1.quantity(),\n");
   fprintf(stderr,"      q2 = s2.quantity();\n");
   fprintf(stderr,"   s.set(s1.name,s1.bar_code,(s1.price()+s2.price())/(q1+q2));\n");
   fprintf(stderr,"   s.quantity(q1+q2);\n");
   fprintf(stderr,"}\n\n");

   fprintf(stderr,"If you already made the change, then check if you are compiling the program\n");
   fprintf(stderr,"with the right file.\n");
   pause();
}
void createfile(char *fname,int bad){
   FILE
      *f = fopen(fname,"w");
   long
      code=1234567890L;
   if(!f){
      fprintf(stderr,"File cr
#include <iostream.h>
#include <string.h>
#include <fstream.h>
#include "salefile.h"
#include "saleitem.h"

//**********************************************************
//
//infile class function defintions
//
//**********************************************************

infile::infile(){
 strcpy(F_Name, "prclist.txt");
 record = 0;
 fin = fopen(F_Name, "r");
 Status = !ferror(fin);
}

infile::infile(const char * FileName){
}

infile::~infile(){
 fclose(fin);
}

int infile::scan(sale_item  &item_out){
 char   Name[41], ch;
 char   BarCode[11];
 float  Price;
 int    i=0;

 //reading the name
 while(ch = (char) getc(fin)){
  if(ch == '\t')
    break;
  Name[i++] = ch;

  if(ferror(fin) || feof(fin)){
    cerr << "Unsuccessful Operation\n";
    Status = 0;
    return 0;
  }
 }

 Name[i] = '\0';

 i = 0;

 //reading the UPC
 while(ch = (char) getc(fin)){
  if(ch == '\t')
    break;
  BarCode[i++] = ch;

  if(ferror(fin)|| feof(fin)){
    cerr << "Unsuccessful Operation\n";
    Status = 0;
    return 0;
  }
 }

 BarCode[i] = '\0';

 //reading the price
 fscanf(fin," %f", &Price);

 if(ferror(fin) || feof(fin)){
    cerr << "Unsuccessful Operation\n";
    Status = 0;
    return 0;
  }

 getc(fin);                         //Grab the \n

 if(!ferror(fin)){
  strcpy(item_out.name, Name);
  strcpy(item_out.bar_code,  BarCode);
  item_out.uprice = Price;
  Status = 1;
  record++;                          //Increment number of records set
 }

 return 1;
}

int infile::fail(){
 return !Status;
}

int infile::count(){
 return record;
}

void infile::reset(){
 rewind(fin);
 record = 0;
 Status = 1;
}

//**********************************************************
//
//outfile class function defintions
//
//**********************************************************


outfile::outfile(){
 strcpy(F_Name, "prclist.txt");
 record = 0;
 fout = fopen(F_Name, "a");
 status = !ferror(fout);
}

outfile::outfile(char a){

 if(a == 'X'){
  strcpy(F_Name, "prclist.txt");
  record = 0;
  fout = fopen(F_Name, "w");
  status = !ferror(fout);
 }
 else{
  strcpy(F_Name, "prclist.txt");
  record = 0;
  fout = fopen(F_Name, "a");
  status = !ferror(fout);
 }
}

outfile::outfile(const char *FileName, char a){
 if(a == 'X'){
 }
 else{
 }
}


outfile::~outfile(){
 fclose(fout);
}

int outfile::write(sale_item  &item_in){
 if(!fail()){
  fprintf(fout,"%s\t%s\t%f\n", item_in.name, item_in.bar_code, item_in.uprice);
  record++;                  //Increment number of records set
  return 1;
 }
 else{
  cerr << "Program failed to open\n";
  status = 0;
  return 0;
 }
}

int outfile::fail(){
 return !status;
}

int outfile::count(){
}

int outfile::flush(){
 int x;

 x = fflush(fout);
 status = !x;

 return status;
}

int outfile::del_data(){
 fclose(fout);
 fout = fopen(F_Name, "w+");
 fprintf(fout,"%d", EOF);

 status = !ferror(fout);

 return !ferror(fout);
}
#include <stdio.h>
#include <stdlib.h>

#ifndef _SALEFILE_H_
#define _SALEFILE_H_

class infile{
   private:
       char       F_Name[20];
       FILE		   *fin;
       int 			record;
       int        Status;
   public:
      friend class sale_item;
      infile();
      infile(const char * FileName);
      ~infile();
      int scan(sale_item  &item_out);
      int fail();
      int count();
      void reset();
};

class outfile{
   private:
      char      F_Name[20];
      FILE      *fout;
      int 		 record;         //keeps track of records in file
      int       status;
   public:
      friend class sale_item;
      outfile();
      outfile(char a);
      outfile(const char *FileName, char a = 'b');
      ~outfile();
      int  write(sale_item  &item_in);
      int  fail();
      int  count();
      int  flush();
      int  del_data();
};
#endif
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include "saleitem.h"
#include "salefile.h"

sale_item::sale_item(){
}

sale_item::sale_item(const char N[],const char C[],double P){
}

sale_item::sale_item(const char C[],int Q){
}

void sale_item::set(const char N[],const char C[],double P){
   strncpy(name,N,40);
   name[40] = '\0';
   strncpy(bar_code,C,10);
   bar_code[10] = '\0';
   uprice = P;
   qntty = 1;
}
void sale_item::set(const char C[],int Q){
   name[0] = '\0';
   strncpy(bar_code,C,10);
   bar_code[10] = '\0';
   qntty = Q;
   uprice = 0;
}


void sale_item::set_ID(void){
   printf("please enter the Code Of the item: ");
   scanf("%10s",bar_code);
   fflush(stdin);
   printf("please enter the quantity: ");
   scanf("%d",&qntty);
   fflush(stdin);
}

void sale_item::set(void){
   printf("please enter the following information for a shopping item.\n");
   printf("name: ");
   scanf("%40[^\n]",name);
   fflush(stdin);
   printf("Bar Code: ");
   scanf("%10s",bar_code);
   fflush(stdin);
   printf("Price: ");
   scanf("%lf",&uprice);
   qntty = 1;
   fflush(stdin);
}

void sale_item::show(void)const{
   printf("\r %-30s | %4d | %8.2lf | %9.2lf\n",
                                      name,qntty,unit_price(),price());
}
void sale_item::showtotal(void)const{
   printf("-------------------------------------------------------------\n");
   printf("\r %46s  %12.2lf\n\n",name,price());
   printf("                                          GST 7%%    %9.2lf\n",gst());
   printf("                                          PST 8%%    %9.2lf\n",pst());
   printf("                                      -----------------------\n");
   printf("                                      Total      %12.2lf\n",Total());
}
double sale_item::gst(void)const{
   return price()*qntty * 0.07;
}
double sale_item::pst(void)const{
   return price()*qntty * 0.08;
}
double sale_item::price(void)const{
   return uprice*qntty;
}
double sale_item::unit_price(void)const{
   return uprice;
}
double sale_item::Total(void)const{
   return price()+ gst() + pst();
}
void sale_item::unit_price(const double p){
   uprice=p;
}
int sale_item::quantity(void)const{
   return qntty;
}
void sale_item::quantity(int q){
   qntty = q;
}
void sale_item::getcode(char *s)const{
   strcpy(s,bar_code);
}
void sale_item::getname(char *n)const{
   strcpy(n,name);
}




sale_item add(const sale_item &s1, const sale_item &s2){
   sale_item      s;

   if(strcmp(s1.bar_code,s2.bar_code) || strcmp(s1.name,"Sub-total") == 0){
      s.set("Sub-total","X",s1.price()+s2.price());
      s.quantity(1);
   }
   else{
      int q1, q2;
      q1  = s1.quantity();
      q2  = s2.quantity();
      s.set(s1.name,s1.bar_code,(s1.price()+s2.price())/(q1+q2));
      s.quantity( q1 + q2);
   }
   return s;
}

sale_item sale_item::operator + (sale_item &s2){
}

sale_item sale_item::operator += (sale_item &s2){
   
   return *this;
}

int sale_item::operator == (sale_item &s2){
 
}
#ifndef SHOPITEM_H
#define SHOPITEM_H
class sale_item{
   private:
      char
         name[41],
         bar_code[11];
      int
         qntty;
      double
         uprice;
   public:
      friend class infile;
      friend class outfile;
      sale_item();
      sale_item(const char NameOfItem[],const char BarCode[],double UnitPrice);
      sale_item(const char BarCode[],int Quantity);
      void set(const char NameOfItem[],const char BarCode[],double UnitPrice);
      void set(const char BarCode[],int Quantity);
      double gst(void)const;
      double pst(void)const;
      double unit_price()const;
      double price(void)const;
      double Total(void)const;
      void getcode(char *)const;
      void getname(char *)const;
      int quantity(void)const;
      void show(void)const;
      void showtotal(void)const;
      void quantity(int Q);
      void unit_price(const double);
      void set_ID();
      void set();
      friend sale_item add(const sale_item &,const sale_item &);

      //overloaded operators
      sale_item operator + (sale_item &s2);
      sale_item operator += (sale_item &s2);
      int operator == (sale_item &s2);
      
};

#endif

Just so we're all clear, your instructor gave you a number of source files which approximately do what you want, but for some reason there are
- some syntax errors
- some missing functionality
which YOU are supposed to fix?

Have you fixed any?

Just so we're all clear, your instructor gave you a number of source files which approximately do what you want, but for some reason there are
- some syntax errors
- some missing functionality
which YOU are supposed to fix?

Have you fixed any?

that what i need to do
fixed first 4 but u need to go one by one to reach 16 im stuck at 4

plz give it a shot

Why do you expect others to do your homework? This approach will never work out on these forums.

Instead show us that you have done some effort and explain what you are having problems with. You say you have fixed 4 out of 16 problems, that means all the other 12 errors you can't fix? Or did you stop trying when you couldn't fix the 5th error.

A better approach would be to paste the error you are getting and paste the code where the error occurs. Then write something what YOU think is wrong and show that you have actually thought about the problem, then we can give you a hint on how to solve the error.

After all you are in school to learn, not to let others do the work for you and copy it.

Comments
Well said

Why do you expect others to do your homework? This approach will never work out on these forums.

Instead show us that you have done some effort and explain what you are having problems with. You say you have fixed 4 out of 16 problems, that means all the other 12 errors you can't fix? Or did you stop trying when you couldn't fix the 5th error.

A better approach would be to paste the error you are getting and paste the code where the error occurs. Then write something what YOU think is wrong and show that you have actually thought about the problem, then we can give you a hint on how to solve the error.

After all you are in school to learn, not to let others do the work for you and copy it.

i said im stuck at 4 need help at this one i dont need the entire home work

but to do 4 u need to open a project and do first three thats my point only

That's not really how it should work. It is good that you include the entire project so that we CAN download and compile it entirely. But that shouldn't be necessary if you give us a clear description of the error and paste the code where the error is occurring (paste the function where the error is and any relevant code we might need to see). Then if this code isn't enough to solve the problem we will download the whole source and look at it.

No offense intended but if you ask your questions like this it only looks like you are asking for others to do your homework. So please copy/paste the error and relevant code (with code tags of course) and tell us a little what you think the error could mean, so that we can see that you have actually thought about it (this is the most important part). Right now we are completely in the dark about what you have tried, what the error is about and we even still need to fix the first 3 errors before we come to the point where we can start helping you?

That's not really how it should work. It is good that you include the entire project so that we CAN download and compile it entirely. But that shouldn't be necessary if you give us a clear description of the error and paste the code where the error is occurring (paste the function where the error is and any relevant code we might need to see). Then if this code isn't enough to solve the problem we will download the whole source and look at it.

No offense intended but if you ask your questions like this it only looks like you are asking for others to do your homework. So please copy/paste the error and relevant code (with code tags of course) and tell us a little what you think the error could mean, so that we can see that you have actually thought about it (this is the most important part). Right now we are completely in the dark about what you have tried, what the error is about and we even still need to fix the first 3 errors before we come to the point where we can start helping you?

thx for nothing guys first time i post no help hehehe

what a forum ...

for the guys who replied i only asked for error 6 to 12 which take approx 5 min for an experianced programmer .... talking to me about morrality like im the immoral person....well if some one is immoral he would be my stupid instructor who gave me a project during finals... well ill appreciate help from someone......its ok to do my project this time forumers im desperate due date is thursday and im stuck what do u want me to tell umore!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Reply With Quote

Comments
Wrong: one of the reasons we're good is because we can fix our own errors. You would be USELESS in the work environment, and we don't like dragging dead weight around. Learn to debug, or find another career.

thx for nothing guys first time i post no help hehehe

what a forum ...

for the guys who replied i only asked for error 6 to 12 which take approx 5 min for an experianced programmer .... talking to me about morrality like im the immoral person....well if some one is immoral he would be my stupid instructor who gave me a project during finals... well ill appreciate help from someone......its ok to do my project this time forumers im desperate due date is thursday and im stuck what do u want me to tell umore!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Reply With Quote

5 minutes? Think again. We'd have to download your files, start a project, see what the problems are, fix them, upload them, tell you what was wrong, post it, etc. We don't even know what the program is supposed to do. And to reiterate what thelamb said, it doesn't look like you've made an attempt yourself or if you have, you haven't posted.

You're in the wrong forum. This is mostly C code. You should probably post there, given headers like these:

#include <iostream.h>
#include <string.h>
#include <fstream.h>

Read this link regarding fstream.h. It's from five years ago, but probably still relevant.

http://www.daniweb.com/forums/thread11430.html

"4) add 2 nodes sale file and sale item"

First I do not know what a sale file is nor a sale item. I do not
bother to download your code to see because most here are too
lazy to do that, including me.

So if you post and show what they are then we could help you.

This article has been dead for over six months. Start a new discussion instead.