Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

I need help in understanding an assignment

I am working on an assignment and my instructor says that I do not have a main method.  I do not understand what is meant by this.  I would appreciate any feedback. I am sure that is a basic program and it is as follows:

"you are the owner of a hardware store and need to keep an inventory that can tell you what different tools you have, how many of each you have on hand, and the cost of each one.  Write a program that initializes the random-access file "hardware.dat" to one hundred empty records, lets you input the data concerning each tool that you no longer have and lets you update any information in the file."  Then information is given regarding the record numbers, tool name, quantity and cost.  

Here is the code that I have in my .cpp file.  

//
#ifndef HardwareData_h
#define HardwareData_h

#include <iostream>

using std::string;

class HardwareData {

public:

      HardwareData (int = 0, string = "", string = "", double = 0.0);

      void setRecordNumber( int );
      int getRecordNumber() const;

      void setToolName(string);
      string getToolName() const;

      void setQuantity(string);
      string getQuantity() const;

      void setCost (double );
      double getCost() const;

private:
      int RecordNumber;
      char ToolName [20];
      char Quantity [4];
      double Cost;

};

#endif


Thank you.


0
klrqueen13
Asked:
klrqueen13
1 Solution
 
grg99Commented:
You have to actually write the code that implements all those nice functions.

for example:

void SetRecordNumber( int r ) {   RecordNumber = r; }
0
 
klrqueen13Author Commented:
Do you mean in say a hardware.h file?  I have been working on this for hours and hours..and am still lost.
0
 
brettmjohnsonCommented:
> I am working on an assignment and my instructor says that I do not have a main method.  
> I do not understand what is meant by this.

Computer programs must have an initial entry point where the program begins execution.
By convention, the c (and c++) runtime library defines that starting point as a function called
main().   By including a function called main() in your program, you are instructing the C runtime
that the program starts 'here'.

0
 
Sys_ProgCommented:
Go thru this link for starting to write your program. It provides an explanation of the main() method etc.

http://computer.howstuffworks.com/c.htm


Regarding your cpp file implementation,

In C++, U should declare the class in a .h (header) file and the implementation (define the class) in a .cpp (iplementation) file.
These links would help

http://www.gamedev.net/reference/articles/article1127.asp
http://juicystudio.com/tutorial/cpp/files.asp
http://www.cprogramming.com/tutorial/lesson12.html


Amit
0
 
itsmeandnobodyelseCommented:
>> Here is the code that I have in my .cpp file

- Move all your code to a file called 'hardwaredata.h'.

- Change

         #include <iostream>

  to

         #include <string>

   in hardwaredata.h


- Add the following include statements to the (now empty) cpp file

    #include "hardwaredata.h"

    #include <iostream>
    #include <string>

    using namespace std;

- Add an implementation for all your class member functions, e. g.

     HardwareData::HardwareData (int RecNum,
                                                  string strToolName,
                                                  string strQuantity ,
                                                   double dCost)
          :  RecordNumber(RecNum)
          , Cost(dCost)
     {
           if (strToolName.length() < sizeof(ToolName))
                strcpy(ToolName, strToolName.cstr());
           else
           {
                  cout << "Tool-Name " << strToolName << ", string is too long " << endl;
           }
               
           if (strQuantity.length() < sizeof(Quantity))
                strcpy(Quantity, strQuantity.cstr());
           else
           {
                  cout << "Quantity " << strQuantity << ", string is too long " << endl;
           }
                         
     }

     void HardwareData::setRecordNumber( int RecNum )
     {
            ...
     }

     int HardwareData::getRecordNumber() const
     {
           ....
     }

     void HardwareData::setToolName(string strToolName)
     {
           ....
     }

     string HardwareData::getToolName() const
     {
          .....
     }

     void HardwareData::setQuantity(string strQuantity)
     {
          ....
     }

     string HardwareData::getQuantity() const
     {
          ....
     }

     void HardwareData::setCost (double dCost)
     {
          ....
     }
 
     double HardwareData::getCost() const
     {
          ....
     }


- Finally, you need a main() function where you can test your class.

  Add the function below all other implementations.

   int main(int nArgs, char* pszArgs[])
   {
         HardwareData hd1;
         hd1.setRecordNumber(1);
         hd1.setToolName("Case");
         ....

         HardwareData pHd2 = new HardwareData(2, "Keyboard", "12", 12.99);  
         double cost = pHd2->getCost();
         ....

         delete pHd2;

         return 0;  
   }


TODO:  replace ....  by  implementation code.

Regards, Alex





0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now