Header Files

Hey guys! I have been trying to do this question in my assignment for almost 1 day straight and I can't figure out the problem. Please guide me.

Here's the question: Design and code a class named Car that holds sales information about a car. Place your class declaration in a header file named Car.h and your function definitions in an implementation file named Car.cpp. Include in your coding all of the statements necessary for your code to compile under a standard C++ compiler.
Upon instantiation, a Car object may receive no parameters or may receive an int holding the odometer reading, a double holding the market value and a null-terminated C-style string holding the make. The odometer reading should be positive-valued but not greater than 999999. The market value should be greater than $499.99. If the object receives a valid number, a valid value and a non-empty string, the object accepts all three values. Otherwise, the object assumes a safe empty state. You may assume that the string holding the make of the car shall not be greater than 30 characters in length.
Your class also includes the following member functions:
• void set(int o, double v, const char* s) - a modifier that changes the data stored in the object only if this function receives valid parameter values. The first parameter receives the odometer reading. The second parameter receives the market value. The third parameter receives the make. If any of the values received is invalid, the object stores a safe empty state. The criteria for validity are listed in the constructor description above.
• int valid(const char* s) const - a query that returns 1 if the string received is the same as the make of the car or as the first part of the make of the car. This function returns 0 otherwise; and
• void display() const - a query that inserts into the standard output stream the odometer reading, the market value, and the make of the car. The odometer reading displays in a field of six, right justified, and zero-filled. The market value displays in a field of ten, right justified, and blank filled. The make of the car displays left-justified in a field of 30.
• Declare a copy constructor for this class

Here's my header file...
1
2
3
4
5
6
7
8
9
10
11
  class Car
{
private:
    int odo;
    double value;
    const char make[15];
public:
	Car() : odo(0), value(0.0), make('NIL') {}
    void set(int o, double v, const char* m[15]);
    void display() const;
};


and here's my .cpp file for the header...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
      #include "car.h"

void car::set(int o, double v, const char m[15])
{
    odo = o;
    value = v;
    make = m;
}

void car::display() const
{
    cout<<setw(8)<<"ODOMETER"<<setw(14)<<"MARKET VALUE"<<setw(14)<<"MODEL & MAKE"<<endl;
    int x;
    for(x=0; x<=10; x++)
    {
        cout<<setw(8)<<odo<<setw(14)<<value<<setw(14)<<make<<endl;
    }
}


and here's my main.cpp file...
1
2
3
4
5
6
7
8
9
10
      #include <iostream>
#include "car.h"
using namespace std;
int main()
{
    Car c1;
    c1.set(89997, 999.99, 'TOYOTA');
    c1.display();
}



Use header guards on your header file.
http://www.cplusplus.com/forum/general/71787/
Topic archived. No new replies allowed.