object oriented programming c++(not checked )

45
Further Programming Concepts in C++ (CE00314-2-FPCOP) Contents 1. Introduction..................................................3 1.1 Project Overview............................................. 3 1.2 Objective of the project.....................................3 1.3 List of presumed assumptions.................................4 1.4 Scope of the project.........................................4 2. Description and justification of the design of the implementation codes............................................. 5 2.1 System Features.............................................. 5 2.2 User Privileges.............................................. 5 2.3 Design (Logical Design) and Justifications...................7 2.3.1 Use Case diagram........................................... 7 2.3.2 Hierarchical chart for proposed system.....................8 2.3.3 Class Diagram............................................. 11 3. Description and Justification of Implementation codes in terms of the OOP Concept.............................................. 13 3.1 Class and Objects........................................... 13 3.2 Data Abstraction and Encapsulation..........................15 3.3 Inheritance................................................. 17 3.4 Polymorphism................................................ 19 3.4.1 Operator overloading and method overloading...............19 3.4.2 Method Overloading........................................19 3.4.3 Parametric overloading and generacity.....................21 4. Description and justification of the validation codes applied into the implementation codes...................................22 4.1 Validations for the menu selections.........................22 4.2 Validation for file operations..............................23 5. Testing and Test Plans.......................................24 5.1 Features to be tested.......................................24 1 Asia Pacific Institute of Information Technology Sri Lanka

Upload: vssen2006

Post on 12-Nov-2014

569 views

Category:

Documents


0 download

DESCRIPTION

This is the project I have done to my C++ projectThis is not the finalized document

TRANSCRIPT

Page 1: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

Contents1. Introduction..................................................................................................................................3

1.1 Project Overview...........................................................................................................................3

1.2 Objective of the project..................................................................................................................3

1.3 List of presumed assumptions........................................................................................................4

1.4 Scope of the project.......................................................................................................................4

2. Description and justification of the design of the implementation codes....................................5

2.1 System Features.............................................................................................................................5

2.2 User Privileges...............................................................................................................................5

2.3 Design (Logical Design) and Justifications...................................................................................7

2.3.1 Use Case diagram.......................................................................................................................7

2.3.2 Hierarchical chart for proposed system......................................................................................8

2.3.3 Class Diagram...........................................................................................................................11

3. Description and Justification of Implementation codes in terms of the OOP Concept.............13

3.1 Class and Objects.........................................................................................................................13

3.2 Data Abstraction and Encapsulation............................................................................................15

3.3 Inheritance...................................................................................................................................17

3.4 Polymorphism..............................................................................................................................19

3.4.1 Operator overloading and method overloading........................................................................19

3.4.2 Method Overloading.................................................................................................................19

3.4.3 Parametric overloading and generacity.....................................................................................21

4. Description and justification of the validation codes applied into the implementation codes. .22

4.1 Validations for the menu selections.............................................................................................22

4.2 Validation for file operations.......................................................................................................23

5. Testing and Test Plans...............................................................................................................24

5.1 Features to be tested.....................................................................................................................24

5.2 Test plan for Login Module.........................................................................................................24

5.3 Test plan for Main Menu Selection.............................................................................................25

5.4 Test plan for Academic Staff Management.................................................................................26

5.5 Test plan for Module Management – Assign Lecturer...............................................................27

5.6 Test plan for Marks Management – View Marks........................................................................27

5.7 Test plan for File Handling..........................................................................................................28

6. Critical Evaluation.....................................................................................................................29

1Asia Pacific Institute of Information Technology

Sri Lanka

Page 2: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

7. Reference...................................................................................................................................30

2Asia Pacific Institute of Information Technology

Sri Lanka

Page 3: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

List of Tables

Table 2.1 User Privileges ……………………………………………………………………..6Table 2.2 File Structure ……………………………………………………………………….9Table 5.1 Test plan for Login Module ………………………………………………………24Table 5.2 Test plan for Menu Module ……………………………………………………….24Table 5.3 Test plan for Academic Staff Menu ………………………………………………25Table 5.4 Test plan for Academic Staff Module …………………………………………….26Table 5.5 Test plan for Module Management ……………………………………………….26Table 5.6 Test plan for Marks management …………………………………………………26Table 5.7 Test plan for File Handling ……………………………………………………….28

3Asia Pacific Institute of Information Technology

Sri Lanka

Page 4: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

List of FiguresFigure 2.1 Case diagram ……………………………………………………………………………………………………………………7Figure 2.2 Privileges diagram …………………………………………………………………………………………………………….8Figure 2.3 Class Diagram …………………………………………………………………………………………………………………10Figure 3.1 Inheritance ……………………………………………………………………………………………………………………..16

4Asia Pacific Institute of Information Technology

Sri Lanka

Page 5: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

List of Abbreviations

C++ C plus plus

SDLC System Development Life Cycle

OO Object Oriented

OOP Object Oriented Programming

UML Unified Modeling Language

5Asia Pacific Institute of Information Technology

Sri Lanka

Page 6: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

1. Introduction

1.1 Project Overview

Manage and keep data of an organisation is one of the most important task. Different organisations or individuals use different approaches to fulfil that. Security of the data, efficiency of the system and reliability of the system are the most essential and important factors of an information management system. Because of it, it is possible to expand, processing and handling capacity of organisation.

Handling data of an organisation using manual system can be risk sensitive data of the organisation because that there can be a leak of the information and it is very difficult to identify where is the system compromise .Also reliability and efficacy of the system depend on it is human resources. Apart form that backup or clone data and keep them safely can be difficult because of its manual format.

To prevent and minimize above risks and gain advantage of technology it is suggest to use computerized information management system. SMS (Student Management system) is windows based console application which allows manage, store and edit complete personal records and examinations results of each student in a university.

As required by assignment, Object Oriented Concept and OO designing pattern have applied with this solution. Apart form that, files use as data storing media and following features have included with the final application

Advanced login with authenticate system for selected user categories

User management Module management Advanced search facility Marks management

Microsoft Visual Studio Team System 2008 and Dot net framework 3.5 have used as main developing and testing platform of this application. Microsoft Visual C++ 6.0 has used as a secondary developing and testing tools. UML has used as modelling method of this application.

1.2 Objective of the project

The main objective of the project is providing a complete solution for handle records of students in a university by using OOP concept and OOP patterns. Main objective can be dividing into further as shown in below.

Provide essential security and privileges to data of the system and its users

Provide capability to handle records of the system6

Asia Pacific Institute of Information Technology Sri Lanka

Page 7: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

Provide reporting capability up to some extends By providing above facilities, increase efficiency , security and

reliability of the system

1.3 List of presumed assumptions

To make more meaningful, feasible and easy of design and develop, following assumptions have made and narrow the scope of the application.

1. The system will only use four type of users2. No of records to be saved in the system is limited 3. Lecturer is assigned to only one module and it is not necessary to trackback previous

assignment details4. Student only allows to take 3 modules per semester and it is not necessary to

trackback previous assignment details5. Batch code of a student will change in every semester6. The system admin will change module assignment of lecturers and enrolments of

students when it required 7. The organisation has enough capability to run and process huge no of files and size of

the application and its component does not matter

1.4 Scope of the project

The scope of the project is developing win32 console application which provides record handling capability of a university. System will enable to system administrators, Administrative staff, academic staff and students to view, enter, modify and delete records based on given privileges.

7Asia Pacific Institute of Information Technology

Sri Lanka

Page 8: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

2. Description and justification of the design of the implementation codes

2.1 System Features

The following modules can be identify as key features of a computer system,

1. User login2. User management

User registration User modification User deletion

3. Module Management Module registration Module modifications Module deletions Assign lecturers Assign student for modules

4. Marks Entering marks Modifying marks

5. Search

Privileges on above features can be varying based on the user type .The following diagram shows users and their privileges

2.2 User Privileges

Privileges Admin Administrative Staff

Academic Staff

Student

User ManagementStudent Management Add View Modify Delete Academic Staff Management Add View Modify Delete Administrative Staff Management Add View

8Asia Pacific Institute of Information Technology

Sri Lanka

Page 9: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

Modify Delete

Module Management

Add View Modify Delete Assign lecturers

Assign student for modules

Marks

Add (Related)

View (Related)

Modify (Related)

Search (Related) (Related)

(Related)

Table 2.1 User Privileges

9Asia Pacific Institute of Information Technology

Sri Lanka

Page 10: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

2.3 Design (Logical Design) and Justifications

UML (Unified Modelling Language) has been used as analysing and design tool of this project. This artefact has developed based on object oriented concept.

2.3.1 Use Case diagram

Following use case diagram shows interaction between users (students, system admin, academic staff and administrative staff) and functions of the current system which is mentioned in case study.This system include 4 actors who inherited from one common actor “User”

.

Figure 2.1 Case diagram

10Asia Pacific Institute of Information Technology

Sri Lanka

Page 11: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

The reason for having four user type inherited form one user is, it is possible to identify some common characteristics between 4 actors. So it is make more sense to generalize user actor in to other 4 user types.

The following diagram shows common privileges of four user type.

Figure 2.2 Privileges diagram

2.3.2 Hierarchical chart for proposed system

As mentioned before system admin has full privileges and other users have limited privileges. In the proposed system different privileges have implemented by restricting menu access for different user levels.

The following table shows attributes of the user types, modules, enrolments and marks

User Marks Module Enrolments

Adm

in

Aca

dem

ic S

taff

M

embe

r

Adm

inis

trat

ive

Sta

ff M

embe

r

Stu

dent

userid : String Markid : String id: String Id:StringStatues : String studentid:String code: String Moduleid :

StringUserpassword : String moduleid: String name: String Studentid:Strin

g11

Asia Pacific Institute of Information Technology Sri Lanka

Login

Admin Menu

User Management

Module Management

Marks

Search

Acadamic Staff Menu

User Management

View Student

Module Management

View Module

Marks

View

Add

Delete

Search

Student Menu

Module Management

View Module

Marks Management

View Marks

Adminstrative Staff Menu

User Managment

View Student

Module Management

View Module

Marks

View Marks

Search

Page 12: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

Fname : String Lecid : String duration: String

BatchCode:String

mname: String Batchcode : String

cordinator: String

lname: String Marktype : String

validility: String

nidno: String Attempt : Integer

gender: String Mark : Floatdateofbirth: Stringdatejoined: Stringnationality: StringaddressLine1: StringaddressLine2: Stringcity: Stringpostalno: Stringcountry: Stringtelephone: Stringmob: Stringemail: StringAdmin

Aca

dem

ic S

taff

M

embe

r

Adm

inis

trat

ive

Sta

ff

Mem

ber

Student

Dateretired String Batch String

Table 2.2 File Structure

12Asia Pacific Institute of Information Technology

Sri Lanka

Page 13: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

2.3.3 Class Diagram

Figure 2.3 Class Diagram

13Asia Pacific Institute of Information Technology

Sri Lanka

Page 14: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

User, Student, “AcademicStaff”, “AdministrativeStaff”, Admin, Module, Marks, Enrolment have identified as main classes of the case study, User handler, File handler, “MarkModule” handler are the support classes which are facilitate to main classes to communicate with each other and reduce the complexity of the relationships.

Student, academic staff, administrative staff and admin inherited form the user class which have common characteristics of all 4 other users. “Userhandler” class manages above mentioned four class’s interconnectivity with each others and “MarkModuleHandler” class which has connected with module and marks classes performs same duty of “Userhandler” class. The Student, “AcademicStaff”, “AdministrativeStaff” and admin classes access marks and module via “MarkModuleHandler” .

Allowing direct access between Student,”AcadamicStaff” , “AdministrativeStaff” , Module , Marks and Enrolment classes without using “MarkModuleHanler” , “FileHandler” and “UserHandler” classes cause to duplication of functions and attributes and reduce the efficiency of the application by unnecessary usage of resources. By centralizing important functions and call them when they required, is increase efficacy of the application and makes more reliable solution.

Enrolment class keeps track on connections between module and student classes. By using Enrolment class it allows to manage and keep track on students’ modules. Also because of using enrolment class it allows to keep details of all existing modules which have followed by a student in a given time duration and reduce unnecessary communications between classes

Although there are lot of drawback of using file as a store media because of project requirements, the data of the system is store in files which handle by “FileHandler” class. It uses binary format to store. Above mentioned table 2.2 demonstrate attributes and type of the data which store in the files. The reason for using binary format to encrypt the data because of that it is possible to protect data from unauthorized access.

14Asia Pacific Institute of Information Technology

Sri Lanka

Page 15: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

3. Description and Justification of Implementation codes in terms of the OOP Concept

As mentioned by Balagurusamy(2008,p7) Object Oriented Programming is an approach that “provides a way to modularizing programs by creating portioned memory area for both data and functions” which mean OOP concept basically based on reusability of components He also mentioned it by” that can be used as template for creating copies on demand” . Modularising real word entitles to software components are also main part of the OOP. Which mean all approaches of OOP based on real world cases.

Because of that it make easy to designer to map logical design with the real world objects and understand the issues and correct them. Class is the basic atomic unit of the OOP.

3.1 Class and Objects

Class can be identified as most imported entity of OOP. In simple way class is the blueprint of an object which mean it has all characteristics and properties which should have on particular object. As mentioned by Microsoft Developer Network (2009) class describe the structure of an object

As mentioned by Sun Developer Network Site (2009) object is an “instance” of a class.

This solution contains 11 different classes which have allocated for different purposes.

Students, Admin, “AdministrativeStaff”, “AcadamicStaff”, Module, Marks, “FileHandler”, “UserHandler” , “MarkModuleHanler” can be identified classes of implemented solution. The following sample codes shows implementation of a class taken in the solution.

class User{ // Start of the class definitionprotected: // Member access specifiers only for derived classes

string userid,statues,userpassword,fname; // data member of the classpublic: // Member access specifiers

User();//Constructor // define the methods user functions void login();// login to the system void logout(); // log out to the system void search(); // search string genarateID(); void veiwUser();

};//End of the class definition

This classes’ method can be implement separately before the initialization / creating an object.

15Asia Pacific Institute of Information Technology

Sri Lanka

Page 16: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

User::void login(){// Implementation of codes}

Like this all class have declared except interface and abstract classes of the solution. When it required to access method or data member of a class it creates an object and access them using member access operator.

The following code shows how to create an object and access the data member or methods of it

//Access members using dot operator

Student istudent;// create a object it takes default constructorIstudent.setUserid(“std001”);//passing string as a argument and set student id

//Access members using -> operator

User *iuser; // create user pointer, Assumed that user is a base class and admin in // derived class of user

Admin iadmin;iuser=&iadmin;//Point iuser to iadmin objectiuser->login();//call login method of iadmin (Assumend login() is a virtual function)

Ideally using classes allow programmer to reuse classes as a blueprint and make objects in different location of the application. And also it makes easy to programmer to manage code and use them effectively. Because of using classes and objects it takes less time to trouble shooting the application.

16Asia Pacific Institute of Information Technology

Sri Lanka

Page 17: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

3.2 Data Abstraction and Encapsulation

Encapsulation and Abstraction are going together words in Object Oriented programming. Abstraction is a one of the most important concept in OOP.

As mentioned by Baldwin (2008) “Abstraction is the definition of an abstract data type, which includes the data type's representation and behaviour.” Which mean represent essential and important details of a class without including the other unnecessary related information. Abstract classes can not be initializing because it is a prototype. Inherited classes should be use to access abstract classes’ method and data members. In C++, Classes which have at least one pure virtual function can be identify as an abstract class. The classes which have only pure virtual function can be identified as interfaces which called another form of an abstraction.

In this solution there is one abstract class which can identified as an interface class. The reason for making “User” class interface is, Student,”AcadamicStaff”,”AdministrativeStaff” and Admin classes have very common characteristics which can be identified as essential and important details of the four classes because of that it allows to share common features between four classes.

The following codes which have extracted form the project shows the how abstract classes have implemented

class User{ // Start of the class definition protected: // Member access specifiers only for derived classes

string userid, statues, userpassword, fname, mname, lname, nidno, gender, dateofbirth,datejoined,nationality,addressLine1,addressLine2,city,postalno,country,tpres,mob,email;// data member of the class

public: // Member access specifiers User();//Constructor // define the methods user functionsvirtual void login()=0;// No return object and no arguments virtual void logout()=0;// No return object and no argumentsvirtual void search()=0;// No return object and no argumentsvirtual string genarateID()=0;// No return object and no argumentsvirtual void veiwUser()=0;// No return object and no arguments

};//End of the class definition

Class “User” is a pure virtual class which mean it is an “interface” class, which have only declarations of the methods but not implemented. Because of that it is not possible to create an object from “User” class.

By creating inherited classes form the “User class” it is possible to access data members and implement functions of the “User” and since it is using virtual functions it is possible to access inherited classes method via a pointer of “User” Which can make code more dynamic

17Asia Pacific Institute of Information Technology

Sri Lanka

Page 18: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

Following codes demonstrate how to access inherited classes’ methods via base class methods. Class “Admin” has inherited form class “User”.

User *iuser; // create user pointer, Assumed that user is a base class and admin in // derived class of user

Admin iadmin;iuser=&iadmin;//Point iuser to iadmin objectiuser->login();//call login method of iadmin (Assumend login() is a virtual function)

Encapsulation can simply explain as “hiding data” According to Balagurusamy E (2008) “Wrapping up data and related functions in to a single class” is the encapsulation he also mentioned that make data members not accessible to outer world but accessible for functions of the same class can be identified as “encapsulation”.

In this solution all data members of the classes access through functions which make data members more secure by limiting access to outer world. Because of that the data of the class can not change by using any other class for the reason that all data members are protected and only accessible for method of the own classes, inherited classes and friend class and functions.

class Marks// Start of the class definition{

private : // Member access specifiers string markid,studentid,moduleid,lecid,batchcode;int attemp;double mark;

public: // Member access specifiers Marks(void);//Constructor virtual ~Marks(void);//Destructors string genarateID();void view();// Setter for set datavoid setMarkid(string);// Set mark idvoid setStudentid(string);// Set student IDvoid setModuleid(string);// Set ModuleIDvoid setLecid(string);// Set LecturerIDvoid setbatchcode(string);//Set Batch Codevoid setattemp(int);//Set Attemptvoid setmark(double);// Set Marks// Getters for fieldsstring getMarkid();// get mark idstring getStudentid();// get student IDstring getModuleid();// get ModuleIDstring getLecid();// get LecturerIDstring getbatchcode();//get Batch Codeint getAttemp();//get Attemptdouble getmark();// get marksbool operator ==(Marks);// Operator Overloading for comparison};

18Asia Pacific Institute of Information Technology

Sri Lanka

Page 19: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

All “getters” get methods take data fields which are only accessible for methods of the class and return it to out. Set methods takes argument from out side of class and assign them to data members of the class. Without using getters and setters of the class out world can not access the data fields of the class.

3.3 Inheritance

As mentioned by Morin (2002) “Inheritance is the concept that when a class of object is defined, any subclass that is defined can inherit the definitions of one or more general classes.” Which mean derived class has same characteristics of base class. The idea of inheritance is “Reusability” because derived class can access all data members (which allowed to inherit by putting access specifiers, protected or public) and functions of the base class. If it required, they can override it without changing base class attributes. Inheritance can be categorized as multiple inheritance, single inheritance, hierarchical inheritance and multilevel inheritance

This solution contains only one hierarchical inheritance. “Student”,”Admin”,” AdministrativeStaff” and ” AcadamicStaff” classes inherit form the “User” class as shown bellow.

Figure 3.1 Inheritance

“Student”,”Admin”,” AdministrativeStaff” and ” AcadamicStaff” classes have all data methods and functions ( Characteristics) of user class because all classes have inherited in publicly. Because of that it is possible to use methods and data members of the “User” interface in derived classes after overriding them. Like this other classes can reuse members of “User” without duplication of the code.

The following code shows the application of inheritance in solution.

Base Class

class User{ // Start of the class definition protected: // Member access specifiers only for derived classes

string userid, statues, userpassword, fname, mname, lname, nidno, gender,

19Asia Pacific Institute of Information Technology

Sri Lanka

Page 20: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

dateofbirth,datejoined,nationality,addressLine1,addressLine2,city,postalno,country,tpres,mob,email;// data member of the class

public: // Member access specifiers User();//Constructor // define the methods user functionsvirtual void login()=0;// No return object and no arguments virtual void logout()=0;// No return object and no argumentsvirtual void search()=0;// No return object and no argumentsvirtual string genarateID()=0;// No return object and no argumentsvirtual void veiwUser()=0;// No return object and no arguments

};//End of the class definition

Derived Class

class Student : public User //Start of the Student Class{private :

string batch;public :

Student():User();//Constructor and invoking base class // constructor

~Student();//Destructor//set functions for attributes

void setUserid(string);//set user idvoid setStatues(string);//set statues of the student

// Set Function Continue...........// Get Varibles

string getUserid();//get user idstring getStatues();//get statues of the student

// Get fntion continue ...............void login();//connect login modulevoid logout();//connect logout modulevoid loadMainMenu();//Load main menuvoid enroll();//Set user enrolment void search();//searchstring genarateID();//Generate student idvoid veiwUser();void viewmodule();void viewmarks();bool operator ==(Student);// Operator Overloadingvoid showCommandConsole(string);

};//End of the student Class

By using inheritance it is possible to implement different type of users which inherited from “User” class by doing minor modification to main class. It is added advantage of using OOP concept in this project.

20Asia Pacific Institute of Information Technology

Sri Lanka

Page 21: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

3.4 Polymorphism

Polymorphism (from the Greek, meaning "many forms") is the quality that allows one name to be used for two or more related but technically different purposes.(Schildt,1998).There are 3 main categories of polymorphism

3.4.1 Operator overloading and method overloading

Operator Overloading

Known as overloading. Operator overloading is provide new meaning to existing operator and provide ability to work with user defined types.

By using operator overloading it is allows to code more meaningful function and apply them in effectively. Also it improves “reusability” of the code. Type casting can also take as a operator overloading.

There are few operators overloading in this solution to improve application coders experience more easily and manage the codes in efficient way. The following codes show applications of an operator overloading in this application.

Overload “==” Operatorbool operator ==(Student istudent)// Operator Overloading for comparison

{//Compare user input if(fname.compare(istudent.getFname())==0 ||

getMname().compare(istudent.getMname())==0 || getLname().compare(istudent.getLname())==0)

return true;//If user inputs are matching return trueelse

return false; //else user inputs are not matching false

}//End of the operator overloading function

3.4.2 Method Overloading

Method Overloading provides new meaning or change behaviour and characteristics of functions which have same name. A method which defined in base class inherited to all derived class and it works as defined in base class. Based on requirements the method in base class can be override to give different functionality.

The following codes show Method overloading in the solution.

21Asia Pacific Institute of Information Technology

Sri Lanka

Page 22: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

Method declaration of string genarateID() in User Class

class User{ // Start of the class definition

public: // Member access specifiers User();//Constructor // define the methods user functionsvirtual string genarateID()=0;// No return object and no arguments

};//End of the class definition

Method Implementation of Student Classstring genarateID()//Start of the genrate ID method

{string str;//Declare str string fstream file; //stream for input AND output//Open the filefile.open("Student.dat",ios::in|ios::out|ios::ate|ios::binary);int last=file.tellg();//move to end of the file and get sizeint loc=last/sizeof(Student);//To Convert Int to string stringstream out;out <<"std"<<loc;str = out.str();return string(str);

}

Method Implementation of “AcadamicStaff” Class

string genarateID()//Start of the genrate ID method{

string str;//Declare str string fstream file; //stream for input AND output//Open the file

file.open("AcadamicStaff.dat",ios::in|ios::out|ios::ate|ios::binary);int last=file.tellg();//move to end of the file and get sizeint loc=last/sizeof(AcadamicStaff);//To Convert Int to string stringstream out;out <<"std"<<loc;str = out.str();return string(str);

}

It is appears to be both method are same but they access different files and use different classes and different type of objects.

22Asia Pacific Institute of Information Technology

Sri Lanka

Page 23: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

3.4.3 Parametric overloading and generacity

There are two way of applying polymorphism via parameters. Parametric overloading gives ability to define number of methods in same class by changing there parameters and return type of it.

The following codes shows use of parametric overloading in the solution.

//Taken form markModuleHandler.hvoid edit(int id,Module &iobject)// To edit Module record of a file

{//Continue …………………….

}

// To edit marks record form a filevoid edit(int attempt,string modid,string stdid,Marks &iobject){

//Continue …………………….

}

Genetacity or parametric overloading allows to creates generic methods which are applicable to range of objects using “Template” concept this can be achieve.

During the development of the solution different class used this concept to reduce unnecessary codes and make more effective application.

// Taken in Admin.h

template<class Tclass>void registerNew(Tclass &iobject){

controller.registerNew(iobject);// This is the methods for create new user)

}

Using template functions reduce unnessory duplication of the coding.To register all four user of the system takes four function but using templates it can be done only using one single function.

23Asia Pacific Institute of Information Technology

Sri Lanka

Page 24: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

4. Description and justification of the validation codes applied into the implementation codes

It required validations to reduce unnecessary logical errors of the application. Due to limited time frame only few validations were implemented.

4.1 Validations for the menu selections

Each and every selection menu of the application only accepts the limited character input including both upper and lower case. If user input invalid character it is prompt an error message and allow user to navigate away based on the menu and location of the application.

// Taken from Admin.hvoid showCommandConsole(string loc){

//continue..............if(loc.compare("mainmenu")==0){

switch (selection){//Continue……….

default: {

system("cls");// To show invalid selection messageui.showInvalidSelectionErrorMessage();cout<<"\t\tType m in crusor for go main menu"<<endl;char ch;cin>>ch;if(ch=='b'|ch=='B'){system("cls");}else if(ch=='e'|ch=='E'){logout();}else if(ch=='m'|ch=='M') {system("cls");loadMainMenu();}

}}

}}

24Asia Pacific Institute of Information Technology

Sri Lanka

Page 25: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

4.2 Validation for file operations File read out operations are most important and an often perform action in the solution. And failure of the file operation might cause to runtime errors. Therefore as special requirement it use validation and failure safely steps in this feature

// Taken form FileHandler.h

void write(string filename,Student &iobject){

try{fstream file; //stream for input AND outputfile.open("Student.dat",ios::in|ios::out|ios::ate|ios::binary);//open the fileint last=file.tellg();//get last memory location of the fileint n=last/sizeof(iobject); //get no of the objects in the filefile.seekp(last); //go to last locationfile.write((char*)&iobject,sizeof(Student))<<flush; //write into filecout<<"Student Record has succsesfuly registred"<<endl;file.close();//close the file

   }catch(...){     cout<<"\t\tFile Handlling Error Please contact system Admin"<<endl;   }

25Asia Pacific Institute of Information Technology

Sri Lanka

Page 26: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

5. Testing and Test Plans

Since all system use same source to call function it was checked all functions logged as an admin except login. The login module checked by logged as all users.

5.1 Features to be tested

Login for different user type

Loading of correct selection menu and forms for user selection

Storing and retrieving of data

Run time error if any

The testing has done based on the modules of the system. The following modules have identified to be tested.

Login Main selection Student Management Academic Staff Management Administrative Staff Management Mark Module Module Management Search

5.2 Test plan for Login Module

Test Case Expected Result Actual Result

Logging as a admin

Login – correct parameter

Display Admin main screen

Login – wrong parameter

Display error message

Logging as a studentLogin – correct parameter

Display student main screen

Login – wrong parameter

Display error message

Logging as a Administrative Staff MemberLogin – correct parameter

Display administrative staff member main screen

Login – wrong parameter

Display error message

26Asia Pacific Institute of Information Technology

Sri Lanka

Page 27: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

Logging as a Academic Staff MemberLogin – correct parameter

Display academic staff main screen

Login – wrong parameter

Display error message

Table 5.1 Test plan for Login Module

5.3 Test plan for Main Menu Selection

Test Case Expected Result Actual Result

Admin Menu

Enter – correct parameter in both upper and lower case

Navigate to relevant module

Enter – wrong parameter

Display error message and prompt user to option to navigate

Student MenuEnter – correct parameter in both upper and lower case

Navigate to relevant module

Enter – wrong parameter

Display error message and prompt user to option to navigate

Administrative Staff MenuEnter – correct parameter in both upper and lower case

Navigate to relevant module

Enter – wrong parameter

Display error message and prompt user to option to navigate

Academic Staff MenuEnter – correct parameter in both upper and lower case

Navigate to relevant module

Enter – wrong parameter

Display error message and prompt user to option to navigate

Table 5.2 Test plan for Menu Module

Since all user menus and functionalities same and call in same source it is use “Academic Staff Management “module to tested other modules. But additional features of the other modules which are not relevant to academic staff management module tested separately.

27Asia Pacific Institute of Information Technology

Sri Lanka

Page 28: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

5.4 Test plan for Academic Staff Management

Academic Staff Management Menu

Test Case Expected Result Actual Result

Academic Staff Menu

Enter – correct parameter in both upper and lower case

Navigate to relevant module

Enter – wrong parameter

Display error message and prompt user to option to navigate

Table 5.3 Test plan for Academic Staff MenuAcademic Staff Forms

Test Case Expected Result Actual Result

Add Academic Staff

Enter – details is fields Navigate to relevant moduleView Academic Staff

Enter correct search parameters in the prompt

Prompt message that it is available and show record and show navigation options at the end

Enter incorrect search parameters in the prompt

Prompt message that it is incorrect and allow user to navigate

Edit Academic StaffEnter correct search parameters in the prompt

Prompt message that it is available and prompt user to edit, after editing ask user confirmation

Enter incorrect search parameters in the prompt

Prompt message that record is not available and allow user to navigate

Accept confirmation message

Update record and show navigation option

Cancel confirmation Show navigationDelete Academic Staff

Enter correct search parameters in the prompt

Prompt message that it is available and editing ask user confirmation

Enter incorrect search parameters in the prompt

Prompt message that record is not available and allow user to navigate

Accept confirmation message

Update(Delete) record and show navigation option

Cancel confirmation Show navigationAssign Lecturer

28Asia Pacific Institute of Information Technology

Sri Lanka

Page 29: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

Enter correct search parameters in the prompt

Prompt message that it is available , prompt user to assign lecturer and ask user confirmation

Enter incorrect search parameters in the prompt

Prompt message that record is not available and allow user to navigate

Accept confirmation message

Update record and show navigation option

Cancel confirmation Show navigation

Table 5.4 Test plan for Academic Staff Module

5.5 Test plan for Module Management – Assign Lecturer

Assign LecturerEnter correct search parameters in the prompt

Prompt message that it is available , prompt user to assign lecturer

Enter required details to the fields

ask user confirmation

Enter incorrect search parameters in the prompt

Prompt message that record is not available and allow user to navigate

Accept confirmation message

Update record and show navigation option

Cancel confirmation Show navigationTable 5.5 Test plan for Module Management

5.6 Test plan for Marks Management – View Marks

Assign LecturerEnter correct search parameters in the prompt

Prompt message that it is available , prompt user to assign lecturer

Enter required details to the fields

ask user confirmation

Enter incorrect search parameters in the prompt

Prompt message that record is not available and allow user to navigate

Accept confirmation message

Update record and show navigation option

Cancel confirmation Show navigationTable 5.6 Test plan for Marks management

29Asia Pacific Institute of Information Technology

Sri Lanka

Page 30: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

All menus of the application accept both upper and lower case letters as selections. When user required to access not implemented or not required feature of the application it shows error message and prompt user to navigate away.

Although some of file read write operations covered in previous test plans and because of all operations used same source file and call them in different locations of the application, file read write operation checked manually in selected cases. To check that add, view and modification features were used.

5.7 Test plan for File Handling

Test Case Expected Result Actual ResultStudent File - Student.dat

Add New Record Show successfully modified message and increase file size

View Record View record according to given parameters

Modify Record Prompt to correct record and update file Academic Staff File - AcadamicStaff.dat

Add New Record Show successfully modified message and increase file size

View Record View record according to given parameters

Modify Record Prompt to correct record and update file Administrative Staff File - AdministrativeStaff.dat

Add New Record Show successfully modified message and increase file size

View Record View record according to given parameters

Modify Record Prompt to correct record and update file Module File - Module.dat

Add New Record Show successfully modified message and increase file size

View Record View record according to given parameters

Modify Record Prompt to correct record and update file Marks File - Marks.dat

Add New Record Show successfully modified message and increase file size

View Record View record according to given parameters

Modify Record Prompt to correct record and update file Enrolment file - Enrolment.dat

Add New Record Show successfully modified message and increase file size

View Record View record according to given parameters

30Asia Pacific Institute of Information Technology

Sri Lanka

Page 31: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

Modify Record Prompt to correct record and update file

Table 5.7 Test plan for File Handling

31Asia Pacific Institute of Information Technology

Sri Lanka

Page 32: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

6. Critical Evaluation

OOP is the latest programming trend in the world. As a software developer, engineer it is necessary to absorb correct techniques and technology to keep in field.”Further Programming Concept in C++” module gives a golden opportunity to polish knowledge and experience of a student.

During the project life cycle, object oriented concept, UML and application of OOP concept have practised. Since this is an individual project a variation of SDLC used to keep track on the project works but with less documentation.

The following facts has identified during the project development

1. Object oriented concept based on mapping real word objects to computer code 2. By using OOP concept , designers and developers find that code

management(maintain and modifying) is easy3. OOP reduce unnecessary duplication of the code and improve reusability of the

application 4. Using OOP, it is possible to implement code library which is integrated all necessary

components, class and abstract classes where implementation details are not allowed to access to other. Because of this feature it is possible to provide secure development environment without giving direct access to base codes.

5. Required more time to initial design time and mapping with the real world entity can be confusing, cause to serious logical errors and always not possible to perform.

By finding above facts, although there are some disadvantages it is determined that using OOP concept cause to reduce lot of problems and increase effectiveness of the code.

32Asia Pacific Institute of Information Technology

Sri Lanka

Page 33: Object Oriented Programming C++(Not Checked )

Further Programming Concepts in C++ (CE00314-2-FPCOP)

7. Reference

Balagurusamy, E.(2008) Object oriented program with c++. New Delhi: Tata McGraw-Hill.

Baldwin,R.G. (2008) Advanced OOP using C++ [online]. Available from: http://www.dickbaldwin.com/AdvOOP/AdvCpp00110.htm#Abstraction.[Accessed 25 August 2009].

Schildt. (1998) Teach Your self C++ [online]. New Delhi: Tata McGraw-Hill. Available from:http://books.google.com/books?id=8uszuvNpFy0C&pg=PA5&dq=he+quality+that+allows+one+name+to+be+used+for+two+or+more+related+but+technically+different+purposes.&ei=wJa0SpzAAqaSkQSaub37Dw#v=onepage&q=&f=false. [Accessed 5 May 2004].

Sun Developer Network Site. (2009) Understanding Instance and Class Members [online]. Available from: http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html.[Accessed 25 August 2009].

Microsoft Developer Network. (2009) Classes: Blueprints for Objects [online]. Available from: http://msdn.microsoft.com/en-us/library/ee5edha0.aspx.[Accessed 25 August 2009].

Morin,R.C. (2002) OOP Concepts by Example [online]. Available from: http://docs.google.com/gview?a=v&q=cache:wif9IvNXHIoJ:www.kbcafe.com/articles/OOP.Concepts.pdf+abstraction+%2B+definition+%2BOOP&hl=en&gl=lk.[Accessed 25 August 2009].

33Asia Pacific Institute of Information Technology

Sri Lanka