PDA

View Full Version : Object Oriented Programming (CS304) Assignment No.4 solution 12/01/2011



Xpert
01-13-2011, 05:48 PM
Assignment

Introduction:

In Assignment No.1 you developed Object Oriented Model for Library Management System and in Assignment #2 you developed its practical prototype in c++ that you didn’t give actual implementation in c++ but simple stereotype (sketch) in the form of c++ code mentioning class names their parameters and functions with access specifiers you also showed the relationship between classes in the form of inheritance mentioning the name of class/classes from which they have been derived in proper c++ syntax.


Description:

As you know in a header file (.h) for a class we include its declaration while in implementation file (.cpp) part we add implementation of all methods of that class. In this assignment you have to do exactly the same for only one class in your Dev c++ project you already had created in Assignment No.2 (Library Management System), you have to add the following for each class,

1. Necessary attributes with suitable data types in its header file (Data Members)
2. Constructor and Destructor of that class
3. Getters and Setters for all its Data Members (also make them const where required)
Important Note:

• In this assignment code given for any class (Library, student, administrator etc) should be correct however you are NOT required to create this class’s objects and call their methods in main these things might be required in next assignment.
• Although it is not requirement you can start from code generated using argoUML for each class.


Uploading Instructions:

You have to upload your single zipped dev c++ project as you did in Assignment No. 2 and 3
Appendix:

Example code for a Course class to store any course attributes is given below similarly you have to add code for all your classes in your Dev c++ project,


Course.h

#include <iostream>
using namespace std;


class Course {

public:

Course(char * , char * , int );
void setName(char *);
char *getName() const ;
void setCode(char *);
char *getCode() const ;
int gerCreditHours();
void setCreditHours(int);
int getCreditHours()const ;
~Course();

private:

char *name;
char *code;
int credithours;

};

Course.cpp

Course::Course(char * _name, char * _code, int _credithours)

{
name = new char[strlen(_name)];
strcpy(name,_name);
code = new char[strlen(_code)];
strcpy(code,_code);
credithours = _credithours;

}

void Course::setName(char * _name)

{
if ( name !=NULL ) delete []name;
name = new char[strlen(_name)];
strcpy(name,_name);

}

char * Course::getName() const

{
return name;

}

void Course::setCode(char * _code)

{
if (code != NULL) delete []code;
code = new char[strlen(_code)];
strcpy(code,_code);


}

char * Course::getCode() const

{
return code;

}

void Course::setCreditHours(int _credithours )

{
credithours = _credithours;

}

int Course::getCreditHours() const

{
return credithours;

}

Course::~Course()
{
if(name != NULL) delete []name;
if (code != NULL) delete []code;
}


Solution can be found in the attachment