Project C++
Project C++
(Project Proposal)
1
ABSTRACT
The report on project entitled "BAUST CGPA Management" is made as a partial fulfillment of
bachelor Degree of Engineering in Computer. The CGPA Calculator Project is a simple console-
based application that calculates the CGPA based on the user's input for theory and lab courses.
The project uses object-oriented programming concepts, such as inheritance, encapsulation, and
polymorphism, to manage and calculate the CGPA. The system supports two types of courses,
theory and lab, each with their own grading criteria. The user can add multiple courses, and the
system will calculate the CGPA based on the courses added. The project demonstrates the use of
abstract classes, virtual functions, and dynamic memory allocation in C++.
2
Contents
Abstract……………………………………………………………………………………………2
Contents…………………………………………………………………………………………...3
Chapter 1………………………………………………………………………………………….5
1.1 Introduction…………………………………………………………………………………5
1.1.1 Objective……………………………………………………………………………………5
Chapter 2………………………………………………………………………………………….7
2.1.1 OOP.……………………………………………………………………………………….7
2.1.3 OBJECT……………………………………………………………………………………7
2.1.4
CLASS……………………………………………………………………………………...7
2.1.5 INHERITANCE……………………………………………………………………………7
2.1.6 POLYMORPHISOM………………………………………………………………………8
Class diagram……………………………………………………………………………...9
Chapter 3………………………………………………………………………………………...10
3.1…...……………………………………………………………………………………………10
3.1.1………………………………………………………………………………………………10
3.1.2………………………………………………………………………………………………10
Fig 1.1……………………………………………………………………………………………10
3.1.4………………………………………………………………………………………………11
Fig 1.2……………………………………………………………………………………………11
3.1.5………………………………………………………………………………………………12
3
Fig 1.3……………………………………………………………………………………………12
Source code……………………………………………………………………………………...13
Chapter 4………………………………………………………………………………………..22
4.1 Discussion…………………………………………………………………………………..22
4
5
Chapter 1
1.1 INTRODUCTION
The CGPA (Cumulative Grade Point Average) Calculator Project is a well-designed and
well-organized console-based application that calculates the CGPA based on the user's input
for theory and lab courses. This project is an excellent example of using object-oriented
programming concepts, such as inheritance, encapsulation, and polymorphism, in C++. The
system supports two types of courses, theory and lab, each with their own grading criteria.
The user can add multiple courses, and the system will calculate the CGPA based on the
courses added. The project consists of several classes and functions to manage and calculate
the CGPA.
1.1.1 OBJECTIVES:
i. To demonstrate the use of object-oriented programming concepts, such as inheritance,
encapsulation, and polymorphism, in C++.
ii. To create an abstract base class Course with a pure virtual function calculatePoints()
and derived classes TheoryCourse and LabCourse that implement this function.
iii. To use dynamic memory allocation in C++ by using an array of Course pointers to
store the created courses.
iv. To use abstract classes and virtual functions in C++ to achieve polymorphism.
v. To create a CGPACalculator class to manage courses and calculate the CGPA based
on the courses added.
vi. To create functions createTheoryCourse() and createLabCourse() to create and return
TheoryCourse and LabCourse objects based on user input.
vii. To create a main() function that initializes a CGPACalculator object, takes user input
for the number of theory and lab courses, and adds the corresponding courses to the
calculator. Finally, it calculates and prints the CGPA based on the added courses.
viii. To ensure that the program handles memory management correctly by deallocating
the memory used by the Course objects in the CGPACalculator destructor.
ix. To create a user-friendly interface that allows users to input course details and
displays the calculated CGPA.
x. To provide a practical example of how to create a simple console-based application
that uses object-oriented programming concepts in C++.
6
1.1.2 Short description:
The CGPA Calculator Project is a console-based application that calculates the Cumulative
Grade Point Average (CGPA) based on user input for theory and lab courses. The project
uses object-oriented programming concepts, such as inheritance, encapsulation, and
polymorphism, to manage and calculate the CGPA. The system supports two types of
courses, theory and lab, each with their own grading criteria. The user can add multiple
courses, and the system will calculate the CGPA based on the courses added. The project
consists of several classes and functions to manage and calculate the CGPA. The Course
class is an abstract base class representing a generic course with a name and credit hours. The
TheoryCourse and LabCourse classes are derived from Course and implement the
calculatePoints() function to calculate the grade points based on the total marks. The
CGPACalculator class manages courses and calculates the CGPA based on the courses
added. The createTheoryCourse() and createLabCourse() functions create and return
TheoryCourse and LabCourse objects based on user input. The main() function initializes a
CGPACalculator object, takes user input for the number of theory and lab courses, and adds
the corresponding courses to the calculator. Finally, it calculates and prints the CGPA based
on the added courses.
7
Chapter 2
The principles of OOP which are used in this project are described below:
2.1.2 OBJECT: In C++, an object is an instance of a class, which is a user-defined data type
that encapsulates data and functions that operate on that data. Objects have their own state,
represented by data members, and behavior, represented by member functions. They allow
for modular programming, data hiding, and code reuse, making them a fundamental concept
in object-oriented programming.
2.1.3 CLASS: In C++, a class is a user-defined data type that encapsulates data and
functions that operate on that data. It consists of member variables (data) and member
functions (methods) that define the behavior of the class. Classes provide a way to organize
and structure code, making it more modular, reusable, and maintainable. They are a
fundamental concept in object-oriented programming and enable the creation of objects,
which are instances of a class.
In C++, constructors are special member functions that are executed automatically when an
object is created. They are used to initialize the object's data members and set up the object's
state. Constructors do not have a return type, not even void. If a constructor is not defined
explicitly, the compiler generates a default constructor that initializes all data members with
their default values.
Destructors, on the other hand, are special member functions that are executed automatically
when an object is destroyed. They are used to clean up any resources that the object has
acquired during its lifetime, such as memory allocated dynamically or file handles opened for
input/output. Destructors have the same name as the class prefixed with a tilde (~) and do not
have any return type, not even void. If a destructor is not defined explicitly, the compiler
generates a default destructor that does nothing.
2.1.4 INHERITANCE: In C++, inheritance is a mechanism where one class acquires the
properties and methods of another class. The class that inherits the properties and methods is
called the derived class, and the class whose properties and methods are inherited is called the
base class. Inheritance allows for code reusability and a more organized code structure. It
enables the creation of hierarchical classifications and promotes the principle of "code to an
interface, not an implementation.
8
I. Base Class (Superclass): The class whose properties and behaviors are inherited by
another class is called the base class or superclass. It serves as a template or blueprint.
II. Derived Class (Subclass): The class that inherits from another class is called the
derived class or subclass. It inherits attributes and methods from the base class and
can also have its own additional attributes and methods.
Function overloading:
Function overloading in C++ allows multiple functions with the same name but different
parameters in the same scope, providing flexibility and convenience for method calling based
on argument types and count.
Operator overloading:
Operator overloading in C++ allows using operators with user-defined types, enabling
custom behavior for arithmetic, relational, and other operators, enhancing code readability
and expressiveness.
9
Class Diagram
<<abstract>>
Course
- name: string
| - creditHours: float
| - totalMarks: float
+ Course() :
+ clculatePoints(): float
+ getCreditHours(): float
+ <<destructor>>()
TheoryCourse
- ct1: float
- ct2: float
- attendance: float
- assignment: float
- midExam: float
- finalExam: float
+ TheoryCourse():
+ calculatePoints(): float
LabCourse CGPACalculator
10
Chapter-3
3.1 IMPLEMENTATION:
3.1.1 Enter the number of theory course:
Fig 1.1
Code:
11
3.1.4 Enter the Numbers:
Fig 1.2
Code:
12
3.1.5 Calculate CGPA:
Fig 1.3
Code:
13
Source Code:
#include <iostream>
#include <string>
class Course {
protected:
string name;
float creditHours;
float totalMarks;
public:
return creditHours;
virtual ~Course() {}
};
14
private:
public:
TheoryCourse(std::string name, float creditHours, float ct1, float ct2, float attendance,
float assignment, float midExam, float finalExam)
return 4.00;
return 3.75;
return 3.50;
return 3.25;
return 3.00;
return 2.75;
return 2.50;
15
} else if (totalMarks >= 135) {
return 2.25;
return 2.00;
} else {
return 0.00;
};
private:
public:
return 4.00;
return 3.75;
16
} else if (totalMarks >= 70) {
return 3.50;
return 3.25;
return 3.00;
return 2.75;
return 2.50;
return 2.25;
return 2.00;
} else {
return 0.00;
};
class CGPACalculator {
private:
Course* courses[MAX_COURSES];
int courseCount;
public:
17
CGPACalculator() : courseCount(0) {}
courses[courseCount++] = course;
} else {
float calculateCGPA() {
totalCreditHours += courses[i]->getCreditHours();
if (totalCreditHours > 0) {
} else {
return 0.0;
~CGPACalculator() {
18
delete courses[i];
};
TheoryCourse* createTheoryCourse() {
string name;
19
return new TheoryCourse(name, creditHours, ct1, ct2, attendance, assignment, midExam,
finalExam);
LabCourse* createLabCourse() {
string name;
20
int main() {
CGPACalculator calculator;
calculator.addCourse(createTheoryCourse());
calculator.addCourse(createLabCourse());
cout << "Your CGPA is: " << cgpa << endl;
return 0;
21
Chapter 4
4.1 Discussion:
This project is a simple CGPA calculator that supports two types of courses: theory and lab.
The system uses object-oriented programming concepts, such as inheritance, encapsulation,
and polymorphism, to manage and calculate the CGPA based on user input. The Course class
is an abstract base class representing a generic course, while TheoryCourse and LabCourse
are derived classes that implement the calculatePoints() function to calculate grade points
based on the total marks. The CGPACalculator class manages courses and calculates the
CGPA based on the courses added.
One potential improvement for this project would be to add error handling for invalid user
input, such as non-numeric values or marks outside the valid range. Additionally, the system
could be extended to support more course types or grading criteria.
Overall, this project demonstrates the use of object-oriented programming concepts in C++
and provides a practical application for managing and calculating grades and CGPA. The
code is well-organized and easy to understand, making it a good starting point for more
complex applications.
22