0% found this document useful (0 votes)
39 views22 pages

Project C++

The document describes a CGPA management project that uses object-oriented programming concepts in C++. It includes classes like Course, TheoryCourse, LabCourse and CGPACalculator to manage courses and calculate CGPA. The project demonstrates inheritance, polymorphism, encapsulation and other OOP principles.

Uploaded by

Rayhan Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views22 pages

Project C++

The document describes a CGPA management project that uses object-oriented programming concepts in C++. It includes classes like Course, TheoryCourse, LabCourse and CGPACalculator to manage courses and calculate CGPA. The project demonstrates inheritance, polymorphism, encapsulation and other OOP principles.

Uploaded by

Rayhan Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

BANGLADESH ARMY UNIVERSITY OF SCIENCE & TECHNOLOGY (BAUST)


SAIDPUR CANTONMENT, NILPHAMARI

(Project Proposal)

Session: 2023-2027 Date:15-04-2024

1. Name of the Students (with ID):


 MD.RAYHAN HAIDAR (ID:0802320105101004)
 NOWRIN ISLAM ERA(ID:0802320105101003)
 MOKBULAR RAHMAN SWEET
(ID:0802320205101032)

2. Name of the Department: Computer Science & Engineering.

3. Program: B.Sc. Engineering in CSE.

4. Group Name: Grade++.

5. Project Name: BAUST CGPA MANAGEMENT.

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++.

Keywords: Object Oriented Programming (OOP), C++

2
Contents

Abstract……………………………………………………………………………………………2

Contents…………………………………………………………………………………………...3

Chapter 1………………………………………………………………………………………….5

1.1 Introduction…………………………………………………………………………………5

1.1.1 Objective……………………………………………………………………………………5

1.1.2 Short description……………………………………………………………………………6

Chapter 2………………………………………………………………………………………….7

2.1 TECHNICAL DESCRIPTION ……………………………………………………………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

2.1 TECHNICAL DESCRIPTION:

The principles of OOP which are used in this project are described below:

2.1.1 OOP: Object-Oriented Programming (OOP) is a programming paradigm that uses


objects to design applications. Objects are instances of classes, which define their properties
and behaviors. OOP emphasizes encapsulation, inheritance, and polymorphism, enabling
code reuse, modularity, and maintainability. It allows for the creation of real-world models,
making complex systems easier to understand and manage.

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.

Constructor and Destructor:

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.

2.1.5 POLYMORPHISM: Polymorphism in C++ is the ability of an object to take on many


forms. It allows objects of different classes to be treated as objects of a common base class,
enabling the use of a single interface to represent multiple types. Polymorphism is achieved
through virtual functions, abstract classes, and interfaces. Virtual functions are functions in a
base class that can be overridden in derived classes to provide specific implementations.
Abstract classes are classes that cannot be instantiated and are used as base classes for other
classes. Interfaces are pure abstract classes that define a set of functions that must be
implemented by derived classes. Polymorphism enables code reuse, simplifies code
maintenance, and enhances code readability.

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:

3.1.2 Enter the name of theory course:

3.1 .3 Credit Hours:

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>

using namespace std;

const int MAX_COURSES = 10;

class Course {

protected:

string name;

float creditHours;

float totalMarks;

public:

Course(std::string name, float creditHours) : name(name), creditHours(creditHours) {}

virtual float calculatePoints() const = 0;

float getCreditHours() const {

return creditHours;

virtual ~Course() {}

};

class TheoryCourse : public Course {

14
private:

float ct1, ct2, attendance, assignment, midExam, finalExam;

public:

TheoryCourse(std::string name, float creditHours, float ct1, float ct2, float attendance,
float assignment, float midExam, float finalExam)

: Course(name, creditHours), ct1(ct1), ct2(ct2), attendance(attendance),


assignment(assignment), midExam(midExam), finalExam(finalExam) {

totalMarks = ct1 * 0.15 + ct2 * 0.15 + attendance + assignment + midExam +


finalExam;

float calculatePoints() const override {

if (totalMarks >= 239) {

return 4.00;

} else if (totalMarks >= 221) {

return 3.75;

} else if (totalMarks >= 210) {

return 3.50;

} else if (totalMarks >= 195) {

return 3.25;

} else if (totalMarks >= 180) {

return 3.00;

} else if (totalMarks >= 169) {

return 2.75;

} else if (totalMarks >= 150) {

return 2.50;

15
} else if (totalMarks >= 135) {

return 2.25;

} else if (totalMarks >= 120) {

return 2.00;

} else {

return 0.00;

};

class LabCourse : public Course {

private:

float attendance, labReport, labMid, viva, finalExam;

public:

LabCourse(std::string name, float creditHours, float attendance, float labReport, float


labMid, float viva, float finalExam)

: Course(name, creditHours), attendance(attendance), labReport(labReport),


labMid(labMid), viva(viva), finalExam(finalExam) {

totalMarks = attendance + labReport + labMid + viva + finalExam;

float calculatePoints() const override {

if (totalMarks >= 80) {

return 4.00;

} else if (totalMarks >= 75) {

return 3.75;

16
} else if (totalMarks >= 70) {

return 3.50;

} else if (totalMarks >= 65) {

return 3.25;

} else if (totalMarks >= 60) {

return 3.00;

} else if (totalMarks >= 55) {

return 2.75;

} else if (totalMarks >= 50) {

return 2.50;

} else if (totalMarks >= 45) {

return 2.25;

} else if (totalMarks >= 40) {

return 2.00;

} else {

return 0.00;

};

class CGPACalculator {

private:

Course* courses[MAX_COURSES];

int courseCount;

public:

17
CGPACalculator() : courseCount(0) {}

void addCourse(Course* course) {

if (courseCount < MAX_COURSES) {

courses[courseCount++] = course;

} else {

std::cout << "Maximum number of courses reached!" << std::endl;

float calculateCGPA() {

float totalPoints = 0.0;

float totalCreditHours = 0.0;

for (int i = 0; i < courseCount; ++i) {

totalPoints += courses[i]->calculatePoints() * courses[i]->getCreditHours();

totalCreditHours += courses[i]->getCreditHours();

if (totalCreditHours > 0) {

return totalPoints / totalCreditHours;

} else {

return 0.0;

~CGPACalculator() {

for (int i = 0; i < courseCount; ++i) {

18
delete courses[i];

};

TheoryCourse* createTheoryCourse() {

string name;

float creditHours, ct1, ct2, attendance, assignment, midExam, finalExam;

cout << "Enter theory course name: ";

cin >> name;

cout << "Enter credit hours: ";

cin >> creditHours;

cout << "Enter marks for CT1: ";

cin >> ct1;

cout << "Enter marks for CT2: ";

cin >> ct2;

cout << "Enter attendance marks: ";

cin >> attendance;

cout << "Enter assignment marks: ";

cin >> assignment;

cout << "Enter mid exam marks: ";

cin >> midExam;

cout << "Enter final exam marks: ";

cin >> finalExam;

19
return new TheoryCourse(name, creditHours, ct1, ct2, attendance, assignment, midExam,
finalExam);

LabCourse* createLabCourse() {

string name;

float creditHours, attendance, labReport, labMid, viva, finalExam;

cout << "Enter lab course name: ";

cin >> name;

cout << "Enter credit hours: ";

cin >> creditHours;

cout << "Enter attendance marks: ";

cin >> attendance;

cout << "Enter lab report marks: ";

cin >> labReport;

cout << "Enter lab mid marks: ";

cin >> labMid;

cout << "Enter viva marks: ";

cin >> viva;

cout << "Enter final exam marks: ";

cin >> finalExam;

return new LabCourse(name, creditHours, attendance, labReport, labMid, viva,


finalExam);

20
int main() {

CGPACalculator calculator;

int numberOfTheoryCourses, numberOfLabCourses;

cout << "Enter the number of theory courses: ";

cin >> numberOfTheoryCourses;

for (int i = 0; i < numberOfTheoryCourses; ++i) {

calculator.addCourse(createTheoryCourse());

cout << "Enter the number of lab courses: ";

cin >> numberOfLabCourses;

for (int i = 0; i < numberOfLabCourses; ++i) {

calculator.addCourse(createLabCourse());

float cgpa = calculator.calculateCGPA();

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.

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.

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

You might also like