Object Oriented Programming Lab: Classes and Objects in C++, Lab Reports of Object Oriented Programming

A class is used to specify the form of an object and it combines data representation and methods for manipulating that data into one neat package. The data and functions within a class are called members of the class. When you define a class, you define a blueprint/conceptual template for a data type. This doesn't actually define any data, but it does define what the class name means, that is, what an object of the class will consist of and what operations can be performed on such an object.

Typology: Lab Reports

2020/2021

Uploaded on 05/29/2021

Sanakhan9973
Sanakhan9973 🇵🇰

2 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Department of Computing
CS212: Object Oriented Programming
Class: BSCS-AB
Lab 02: Classes and Objects
Date: 08-03-21
Instructor: Anum Asif / Rabbia Hasan
NAME: AZKA KHAN
CMS ID: 297896
SECTION A
CS212: Object Oriented Programming Page 1
pf3
pf4
pf5

Partial preview of the text

Download Object Oriented Programming Lab: Classes and Objects in C++ and more Lab Reports Object Oriented Programming in PDF only on Docsity!

Department of Computing

CS212: Object Oriented Programming

Class: BSCS-AB

Lab 02: Classes and Objects

Date: 08-03-

Instructor: Anum Asif / Rabbia Hasan

NAME: AZKA KHAN

CMS ID: 297896

SECTION A

Lab 02: Classes and Objects

Introduction

This lab is about familiarization with the difference between class and object.

Objective

To understand the difference between class and object. Students would be able to use objects in

their programming and understand the object oriented paradigm

Tools/Software Requirement

 Microsoft Visual Studio

Description

A class is used to specify the form of an object and it combines data representation and methods

for manipulating that data into one neat package. The data and functions within a class are called

members of the class.

When you define a class, you define a blueprint/conceptual template for a data type. This doesn't

actually define any data, but it does define what the class name means, that is, what an object of

the class will consist of and what operations can be performed on such an object.

Syntax

class Box

public:

double length; // Length of a box

double breadth; // Breadth of a box

double height; // Height of a box

int main ()

Box b1; // Object b

b1.length = 10;

b1.breadth = 10;

CODE:

#include using namespace std; class BSCS10 { public: int age; int roll_number; double markS1; double markS2; double markS3; int percentage1(double a, double b, double c) { int percentage; return percentage = ((a + b + c) / 300) * 100; } }; int main() { BSCS10 student1; student1.age = 18; student1.roll_number = 297896; cout << "Please enter student's marks in three subjects." << endl; cout << "Subject 1:"; cin >> student1.markS1; cout << "Subject 2:"; cin >> student1.markS2; cout << "Subject 3:"; cin >> student1.markS3; int result = student1.percentage1(student1.markS1, student1.markS2, student1.markS3); cout << "\n\n"; cout << "******************************\n" <<endl; cout << "* Student's Age:" << student1.age << "\n* Roll Number:" << student1.roll_number << "\n* Marks in subject 1 :" << student1.markS1 << "\n* Marks in subject 2 :" << student1.markS2 << "\n* Marks in subject 3 :" << student1.markS3 << endl; cout << "* Percentage= " << result << "%"; if (result >= 90) cout << "\n* Student grade: A"; else if (result >= 80) cout << "\n* Student grade: B+"; else if (result > 70) cout << "\n* Student grade: B"; else if (result > 60) cout << "\n* Student grade: C"; else if (result > 50) cout << "\n* Student grade: D"; else

cout << "\n* Student grade: F"; cout << "\n\n******************************\n\n\n" << endl; system("pause"); }

OUTPUT: