Exercise problem

From: Keith (asdth_at_hotmail.com)
Date: 05/31/04


Date: Mon, 31 May 2004 16:11:44 +0100

Im working my way through a few example exercises from a book called "Learn
C++ in 24 Hours". Ive come across a 2 part exercise, the first part being:

      Create a class to model a student object as an abstract data type
(name it Student). Some of the attributes and methods needed by the class
to hold and update data for any student created using this data type are as
depicted in the diagram below. The diagram shows the name of a class
followed by its methods and attributes respectively.

      STUDENT

      Student Number

      Student Name

      Student Fee

      Amount Paid

      Fee Balance

      get Student Number

      get Student Name

      get Fee Payable

      get Fee Balance

      get Amount Paid

      set Student Number

      set Student Name

      set Fee Payable

      pay Fee

Ive worked through this as follows, lol im pretty sure its correct, so
forgive me if theres anyerrors so here goes:

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

class Student{

  int studentnumber;
  char studentname[50];
  float studentfee;
  float amountpaid;
  float feebalance;

  //methods
public:

 /*get Student Number
 get Student Name
 get Fee Payable
 get Fee Balance
 get Amount Paid
 set Student Number
 set Student Name
 set Fee Payable
 pay Fee*/

 void setstudentnumber(int);
 int getstudentnumber();

 void setstudent();
 char* getstudentname();

 void setstudentfee(float);
 float getstudentfee();

 void setamountpaid(float);
 float getamountpaid();

 void setfeebalance();
 float getfeebalance();

 Student();
 Student(char*, int, float);
 Student(int);

 //constructors

};

void StockItem::setunitprice(float price)

{
 unitprice = price;
}

float StockItem::getunitprice()

{
 return unitprice;

}

void StockItem::getdetails()

{
 cout << "Item Number: " << itemnumber << endl;
 cout << "Stock Level: " << stocklvl << endl;
 cout << "Unit Price: " << unitprice << endl;
}

void StockItem::setitemnumber(int number)

{
 itemnumber = number;
}

void StockItem::setstocklvl(int stocknumber)

{
 stocklvl = stocknumber;
}

int StockItem::getstocklvl()

{
 return stocklvl;
}

StockItem::StockItem()
{
 strcpy(name, "No Item Name");
 cout << "Item Name is: " << name << endl;
 cout << "Enter a name: " << endl;
 cin >> name;
 cout << "Item Name is: " << name << endl;
}

StockItem::StockItem(char theName[50], int number, float price)
{
 strcpy(name, name);
 itemnumber = number;
 unitprice = price;
}

void main()

{

 StockItem MyStock;

 MyStock.setstocklvl(1);
 MyStock.setitemnumber(1);
 MyStock.setunitprice(45);
 MyStock.getdetails();

}

Now ive compiled this and run it, it seems fine, however the next part of
the question, which im not even sure where to start is:

Using the 'STUDENT' class methods above, write a program to test the methods
as follows:

¨ Create 4 student objects, 2 with fee payable of $390.15, and
the other two with fee of $700.89 and $154.99 respectively.

¨ Set the student number (ID) to 1001, 1002, 2007, 2009
respectively.

¨ Set the names of the students.

¨ Credit Student numbers 1001 and 2007 with $116.53 (amount
paid) respectively.

¨ Display all the student numbers, names and balances.

Sorry to be a bother, but any help would be greatly appreciated. Do I need
to rewrite a complete new program or can I change the one ive already
created?

Thanks

Keith



Relevant Pages