I am new to C++ and I found the following code in a text book:
For what I see they do not use a header; I am using Visual C++ and the structure that they give me is with a header so I programmed the following:
//parts.h
#pragma once
class parts
{
private:
int idModel;
int idPart;
float cost;
public:
parts(void);
virtual ~parts(void);
void setPart(int,int np,float);
void showParts();
};
//parts.cpp
#include <iostream>
#include "parts.h"
using namespace std;
parts::parts(void)
{
}
parts::~parts(void)
{
}
void parts::setPart(int nm, int np, float c)
{
idModel=nm;
idPart=np;
cost=c;
}
void parts::showParts()
{
cout<<"Model, "<<idModel;
cout<<" part "<<idPart;
cout<<" cost\n "<<cost;
}
//main program
#include <iostream>
#include "parts.h"
using namespace std;
int main(void)
{
parts p;
p.setPart(569,10,55.55);
p.showParts();
system("PAUSE");
}
so which one is the correct one? to use or not to use headers in this situation? what would be the possible drawbacks of not doing that.
Thanks