-1

I'm having issues utilising header file that I created. Object from the class defined in invoice is not created in the main method.

Here's the contents of my header file that I made:

invoice.h

#pragma once
#include <string>
#include<iostream>
#include"stdafx.h";
using namespace std;
class Invoice
{
private:
    string partno, description;
    int quantity, price;
public:
    Invoice(string partno, string description; int quantity, price);
    //void partno(string);
    //void description(string);
    //void quantity(int);
    //void price(int);
    int getinvoiceamount();

    string getPartno() {
        return partno;
    }
    string getDescription(){
        return description;
    }
    int getQuantity(){
    return quantity;
}
    int getPrice(){
        return price;
    }

    void setPartno(int partno)
    {
        Invoice::partno=partno
    }
    void setDescription(int discripyion)
    {
    Invoice::description=description    
    }
    void setQuantity(int quantity);
    {
    Invoice::quantity=quantity
    }
    void setPrice(int price);
    {
    Invoice::price=price
    }

    ~Invoice();
};

Here's the contents of the file where I'm using my header file:

invoice.cpp

#include "stdafx.h"
#include "invoice.h"
#include "stdafx.h"
#include "Account.h"
#include<iostream>
#include<conio.h>
#include <string>
using namespace std;


int invoice::getinvoiceamount()
{
    return (getquantity*getprice)
    if (quantity != 0)
        quantity = 0;
    if (price != 0)
        price = 0;
}


hardware::~hardware()
{
}

Just let me know where I'm doing wrong!

  • You are missing the implementation of an Invoice constructor and destructor. – Estiny Sep 09 '15 at 11:54
  • 7
    Please learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve), and also [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). – Some programmer dude Sep 09 '15 at 11:56
  • 1
    `int invoice::getinvoiceamount()` -> `int Invoice::getinvoiceamount()` c++ is a case sensitive language. – πάντα ῥεῖ Sep 09 '15 at 12:10
  • 3
    I'm voting to close this question as off-topic because there are so many errors in that code that it seems to be too broad of being salvable and useful for future research. – πάντα ῥεῖ Sep 09 '15 at 12:12

1 Answers1

1

After correcting most of the obvious mistakes, implementing a constructor, adding some comments to clarify members and functions leads to:

header:

pragma once
#include <string>
#include<iostream>
#include"stdafx.h";
using namespace std;
class Invoice{
public:

    // constructor implementation: data member initialization added
    Invoice(string part, string descr; int quant, pric)
    : partno(part), description(descr), quantity(quant), price(pric) { }
    // use default destructor 
    // ~Invoice();
    //void partno(string);
    //void description(string);
    //void quantity(int);
    //void price(int);

    // non-modifying member functions: getters
    int getInvoiceAmount();
    string getPartno(){ return partno; }
    string getDescription(){ return description; }
    int getQuantity(){ return quantity; }
    int getPrice(){ return price; }

    // modifying member functions: setters
    void setPartno(int part){ partno=part;}
    void setDescription(int discr){ description=descr; }
    void setQuantity(int quant);{ quantity=quant; }
    void setPrice(int pri){ price=pri; }
private:

    string partno;
    string description;
    int quantity;
    int price;
}; 

cpp

#include "stdafx.h"
#include "invoice.h"
#include "stdafx.h"
#include "Account.h"
#include<iostream>
#include<conio.h>
#include <string>
using namespace std;

// be consistent with the names of variables/ functions
int Invoice::getInvoiceAmount(){
    // check either if some of the variables in question have values that doesn't make sense
    // if (quantity == 0) error("No quantity!");
    // if (price == 0) error("No price!");
    // or the opposite
    if(quantity != 0 && price != 0) return (getquantity * getprice);   
    else error("Quantity or price == 0");   
}

// what is this? Add comments to clarify the purpose of your functions/ variables
// hardware::~hardware()
// {
// }
Ziezi
  • 6,375
  • 3
  • 39
  • 49