Project 08
Home ] Up ]

 

//Project07.cpp
//Date 09/14/2001
//Auothor: Us

#include <iostream.h>
#include <string.h>


int const MAX_LEN = 20;

const char *testNames[] = {
  "Chair", "Table", "Spoon", "Book", "Pen", "Eraser",
  "TV", "Stereo", "VCR", "DVD Player", "XBox", "Microwave",
  "Toaster", "Car", "Phone", "Couch", "Calculator",
  "Cookies"};

const int MAX_NAMES = sizeof(testNames)/sizeof(testNames[0]);



void testInput(void);
void testSetName(void);
void testSetWeight(void);
void testConstructor(void);
void testConstructorCh(void);


class CItem
  {
  private:
    char m_name[MAX_LEN+1];
    int m_weight;
  public:
    CItem(void);
    void input(void);
    void display(void);
    void set(char name[], int weight);
    void setName(char name[]);
    void setWeight(int weight);

    CItem(char name[], int weight); //09/17/2001
    CItem(char ch); // CItem item('r');


  };




void main(void)
  {
  //testInput();
  //testConstructor();
  testConstructorCh();

  /*
  CItem item;
  item.display();

  CItem *p;
  p = &item;
  (*p).display();
  p->display();
  */

  /*
  CItem items[500];
  for (int i=0; i<=499; i++)
    items[i].display();
  */


  /*
  CItem item;
  item.set("Hammer", 200);
  item.display();

  char tname[15];
  int tweight;
  cin >> tname;
  cin >> tweight;
  item.set(tname, tweight);
  item.display();
  */



  /*
  if (item1 == item2)
    cout << "== works\n";
  */

  /*
  cout << item1;
  */

  /*
  if (item1 != item2)
    cout << "!= works\n";
  */

  /*
  cin >> item1;
  */

  }


//CItem (ch) constructor
/* constructs an object with random name and weight
*/
CItem::CItem(char ch)
  {
  

  }

void testConstructorCh(void)
  {
  cout << MAX_NAMES << endl;
  CItem item("Chair", 150);
  item.display();
  }


    
//CItem (name, weight) constructor
/* constructs an object with given name and weight
*/
CItem::CItem(char name[], int weight)
  {
  strcpy(m_name, name);
  m_weight = weight;
  }

void testConstructor(void)
  {
  CItem item("Chair", 150);
  item.display();
  }


void CItem::display(void)
  {
  cout << "item info: ";
  cout << m_name << ", ";
  cout << m_weight << endl;
  }


CItem::CItem(void)
  {
  cout << "Constructor called\n";
  strcpy(m_name, "");
  m_weight = 0;
  }



///////////////////////////////////////////
//input function
///////////////////////////////////////////
/*
  This is a member function for CItem class
  it gets the name and weight from the keyboard
  and sets the values of name and weight data members
*/
void CItem::input(void)
  {
  cout << "item m_name:   ";
  cin >> m_name;
  cout << "item m_weight: ";
  cin >> m_weight;
  }


void testInput(void)
  {
  cout << "test input function member\n";
  CItem item1;
  item1.display();
  item1.input();
  item1.display();
  }


void CItem::set(char name[], int weight)
  {
  strcpy(m_name, name);
  m_weight = weight;
  }


/* SAMPLE RUN
test input function member
Constructor called
item info: , 0
item m_name:
*/