|
//Project07.cpp //Date 09/14/2001 //Auothor: Us #include <iostream.h> #include <string.h> int const MAX_LEN = 20; void testInput(void); void testSetName(void); void testSetWeight(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); }; void main(void) { /* 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(); */ testInput(); /* if (item1 == item2) cout << "== works\n"; */ /* cout << item1; */ /* if (item1 != item2) cout << "!= works\n"; */ /* cin >> item1; */ } 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: */ |