All right so I'm learning C++ via library books and the information isn't too helpful, but it's the best I can find. Most of the books at my library are older than I am - copyright 1993 - some even earlier. So it's kind of ironic how the [seemingly] simplest thing in C++ (including a header file) can possibly be so hard. I'm working on one of the examples from the book - C++ For Dummies. I copied down an example about classes and objects, meanwhile the main problem is finding out how to include the header file. Here's the main and the header file. It would greatly appreciate me if someone were to please help me. Thanks in advance! =)
main.cpp
#include <iostream>
#include <cstdlib>
#include "Pen.h"
using namespace std;
int main(int argc, char *argv[]) {
Pen FavoritePen;
FavoritePen.InkColor = blue;
FavoritePen.ShellColor = clear;
FavoritePen.CapColor = black;
FavoritePen.Style = ballpoint;
FavoritePen.Length = 6.0;
FavoritePen.Brand = "Pilot";
FavoritePen.InkLevelPercent = 90;
Pen WorstPen;
WorstPen.InkColor = blue;
WorstPen.shellColor = red;
WorstPen.CapColor = black;
WOrstPen.Style = felt_tip;
WorstPen.Length = 3.5
WorstPen.Brand = "Acme Special";
WorstPen.InkLevelPercent = 100;
cout << "This is my favorite pen" <<endl;
cout << "Color: " << FavoritePen.InkColor << endl;
cout << "Brand: " << FavoritePen.Brand << endl;
cout << "Ink Level: " << FavoritePen.InkLevelPercent << "%" << endl;
FavoritePen.write_on_paper("Hello, I am a pen");
cout << "Ink Level: " << FavoritePen.InkLevelPercent << "%" << endl;
system("PAUSE");
return 0;
}
Pen.h
#include <string>
enum Color {blue, red, black, clear};
enum Penstyle {ballpoint, felt_tip, fountain_pen};
class Pen {
public:
Color InkColor;
Color ShellColor;
Color CapColor;
PenStyle Style;
float Length;
string Brand;
int InkLevelPercent;
void write_on_paper(string words) {
if (InkLevelPercent <=0) {
cout << "Oops! Out of ink!" << endl;
}
else {
cout << words << endl;
InkLevelPercent = InkLevelPercent - words.length();
}
}
void break_in_half() {
InkLevelPercent = InkLvelPercent / 2;
Length / 2.0;
}
void run_out_of_ink() {
InkLevelPercent = 0;
}
};