SlideShare a Scribd company logo
1 | P a g e
CS-212 Object Oriented Programming
National University of Sciences and Technology
School of Electrical Engineering and Computer Science
CS-212 Object Oriented Programming
LAB No. 02
Section: BEE 12-C
Submitted to: Ms. Shakeela Bibi
Instructor: Dr. Khuram Shahzad
Name CMS ID
Ahamed Musharaf 356481
2 | P a g e
CS-212 Object Oriented Programming
LAB TASKS
Task
Develop a program that implements a C++ class “Student” with following data members
 Age
 Roll Number
 markSubject1
 marksSubject2
 marksSubject3
The class should define a method/function to calculate percentage from marks obtained in three subjects.
Finally, you’ll create objects of Student class, initialize their data members through set and get functions,
calculate percentages, determine grades and print summary in the end.
Code:
//The given code defines a class Student
//The function getinfo() accepts the age,student roll no, and marks of three subjects
from the user and putdata() display this information.
#include <iostream>
#include <stdio.h>
using namespace std;
//Class which contains the attributes of Students
class student
{
private:
int age, rollno;
int m1, m2, m3;
public:
void getinfo() //getting info from user about the student
{
cout << "Enter Student Age: ";
cin >> age;
cout << "Enter Student Roll No: ";
cin >> rollno;
cout << "Enter the marks obtained in Subject1: ";
cin >> m1;
cout << "Enter the marks obtained in Subject2: ";
3 | P a g e
CS-212 Object Oriented Programming
cin >> m2;
cout << "Enter the marks obtained in Subject3: ";
cin >> m3;
}
//calculating percentage
float getPercentage()
{
float percentage;
//converting the integer percentage calculated into float percentage using
static_cast function
percentage = static_cast <float>(m1 + m2 + m3) / 3;
return percentage;
}
//calculating the Grade obtained by the student
char getGrade()
{
char grade;
float percentage = getPercentage();
if (percentage < 40) {
return 'F';
}
else if (percentage < 50) {
return 'D';
}
else if (percentage < 60) {
return 'C';
}
else if (percentage < 75) {
return 'B';
}
else {
return 'A';
}
}
void putdata() // to get the summary
{
cout << "Age: " << age << endl;
cout << "Roll number: " << rollno << endl;
cout << "Marks obtained in Subject1: " << m1 << endl;
cout << "Marks obtained in Subject2: " << m2 << endl;
cout << "Marks obtained in Subject3: " << m3 << endl;
cout << "Percentage: " << getPercentage() << endl;
cout << "Grade obtained: " << getGrade() << endl;
}
};
int main() {
//student object s1 and s2 created in main
4 | P a g e
CS-212 Object Oriented Programming
//The age, roll no, and marks are ontained from the user by using the class
student
student s1;
student s2;
cout << "Enter below the details of the student Ahamed," << endl;
s1.getinfo();
cout << "n";
cout << "Enter below the details of the student Musharaf," << endl;
s2.getinfo();
cout << "n";
//displaying the percentage and grade of both the students using the created
getPercentage and getGrade functions
cout << "Ahamed's percentage is: " << s1.getPercentage() << endl;
cout << "Musharaf's percentage is: " << s2.getPercentage() << endl;
cout << "n";
cout << "Ahamed's grade is: " << s1.getGrade() << endl;
cout << "Musharaf's grade is: " << s2.getGrade() << endl;
cout << "n";
//Display of summary of both the students
cout << "Ahamed's summary: " << endl;
s1.putdata();
cout << "n";
cout << "Musharaf's summary: " << endl;
s2.putdata();
return 0;
}
5 | P a g e
CS-212 Object Oriented Programming
6 | P a g e
CS-212 Object Oriented Programming
Output:
7 | P a g e
CS-212 Object Oriented Programming

More Related Content

DOCX
LAB 1 Report.docx
PPTX
Data structures Lecture no. 4
PPTX
Activities on Software Development
PDF
Ge6161 lab manual
PPTX
Sajid Ali reg # 016
PPTX
Introduction of calculus in programming
PDF
Program to be written for C Output: program to compute e. The calculation of...
PDF
LAB 1 Report.docx
Data structures Lecture no. 4
Activities on Software Development
Ge6161 lab manual
Sajid Ali reg # 016
Introduction of calculus in programming
Program to be written for C Output: program to compute e. The calculation of...

What's hot (18)

PPTX
More on Data Types (Exponential and Scientific Notations)
PDF
PPT
Tcs nqt 2019 p 2
DOCX
Resume
PDF
Python programs
PDF
Pascal for beginers tute
PDF
Code Optimizatoion
PDF
201505 CSE340 Lecture 04
DOCX
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
PDF
201505 CSE340 Lecture 03
PPTX
Object oriented programming 7 first steps in oop using c++
PDF
201505 - CSE340 Lecture 01
PPTX
PPSX
Write programs to solve problems pascal programming
PDF
201506 CSE340 Lecture 10
PPTX
halstead software science measures
PPTX
Evaluation of postfix expression using stack
PDF
More on Data Types (Exponential and Scientific Notations)
Tcs nqt 2019 p 2
Resume
Python programs
Pascal for beginers tute
Code Optimizatoion
201505 CSE340 Lecture 04
CLASS VIII COMPUTERS FLOW CHART AND ALGORITHM
201505 CSE340 Lecture 03
Object oriented programming 7 first steps in oop using c++
201505 - CSE340 Lecture 01
Write programs to solve problems pascal programming
201506 CSE340 Lecture 10
halstead software science measures
Evaluation of postfix expression using stack
Ad

Similar to LAB 2 Report.docx (20)

DOCX
Report-Template.docx
DOCX
CCE management system
PDF
22316-2019-Summer-model-answer-paper.pdf
PDF
Can someone help me with this code When I run it, it stops after th.pdf
PDF
OOPS_Lab_Manual - programs using C++ programming language
DOCX
Abstract Classes Interface Exceptional Handling Java
PDF
#include -string- #include -string- #include -vector- #include -iostre (1).pdf
PDF
How to write you first class in c++ object oriented programming
PDF
Online_Examination
DOCX
computer science project
PPTX
12Structures.pptx
PDF
DEBUG3 This program creates student objects and overl.pdf
DOC
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
PPTX
OOPS 22-23 (1).pptx
PDF
How to implement g rpc services in nodejs
PDF
College management
DOCX
GPA calculator and grading program in c++
PPT
Lecture07
PPTX
05 Object Oriented Concept Presentation.pptx
PPTX
Inheritance.pptx
Report-Template.docx
CCE management system
22316-2019-Summer-model-answer-paper.pdf
Can someone help me with this code When I run it, it stops after th.pdf
OOPS_Lab_Manual - programs using C++ programming language
Abstract Classes Interface Exceptional Handling Java
#include -string- #include -string- #include -vector- #include -iostre (1).pdf
How to write you first class in c++ object oriented programming
Online_Examination
computer science project
12Structures.pptx
DEBUG3 This program creates student objects and overl.pdf
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
OOPS 22-23 (1).pptx
How to implement g rpc services in nodejs
College management
GPA calculator and grading program in c++
Lecture07
05 Object Oriented Concept Presentation.pptx
Inheritance.pptx
Ad

Recently uploaded (20)

PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Download FL Studio Crack Latest version 2025 ?
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
assetexplorer- product-overview - presentation
PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PPTX
Patient Appointment Booking in Odoo with online payment
Autodesk AutoCAD Crack Free Download 2025
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Download FL Studio Crack Latest version 2025 ?
How to Choose the Right IT Partner for Your Business in Malaysia
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Design an Analysis of Algorithms II-SECS-1021-03
Wondershare Filmora 15 Crack With Activation Key [2025
Design an Analysis of Algorithms I-SECS-1021-03
assetexplorer- product-overview - presentation
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Monitoring Stack: Grafana, Loki & Promtail
Computer Software and OS of computer science of grade 11.pptx
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Oracle Fusion HCM Cloud Demo for Beginners
Patient Appointment Booking in Odoo with online payment

LAB 2 Report.docx

  • 1. 1 | P a g e CS-212 Object Oriented Programming National University of Sciences and Technology School of Electrical Engineering and Computer Science CS-212 Object Oriented Programming LAB No. 02 Section: BEE 12-C Submitted to: Ms. Shakeela Bibi Instructor: Dr. Khuram Shahzad Name CMS ID Ahamed Musharaf 356481
  • 2. 2 | P a g e CS-212 Object Oriented Programming LAB TASKS Task Develop a program that implements a C++ class “Student” with following data members  Age  Roll Number  markSubject1  marksSubject2  marksSubject3 The class should define a method/function to calculate percentage from marks obtained in three subjects. Finally, you’ll create objects of Student class, initialize their data members through set and get functions, calculate percentages, determine grades and print summary in the end. Code: //The given code defines a class Student //The function getinfo() accepts the age,student roll no, and marks of three subjects from the user and putdata() display this information. #include <iostream> #include <stdio.h> using namespace std; //Class which contains the attributes of Students class student { private: int age, rollno; int m1, m2, m3; public: void getinfo() //getting info from user about the student { cout << "Enter Student Age: "; cin >> age; cout << "Enter Student Roll No: "; cin >> rollno; cout << "Enter the marks obtained in Subject1: "; cin >> m1; cout << "Enter the marks obtained in Subject2: ";
  • 3. 3 | P a g e CS-212 Object Oriented Programming cin >> m2; cout << "Enter the marks obtained in Subject3: "; cin >> m3; } //calculating percentage float getPercentage() { float percentage; //converting the integer percentage calculated into float percentage using static_cast function percentage = static_cast <float>(m1 + m2 + m3) / 3; return percentage; } //calculating the Grade obtained by the student char getGrade() { char grade; float percentage = getPercentage(); if (percentage < 40) { return 'F'; } else if (percentage < 50) { return 'D'; } else if (percentage < 60) { return 'C'; } else if (percentage < 75) { return 'B'; } else { return 'A'; } } void putdata() // to get the summary { cout << "Age: " << age << endl; cout << "Roll number: " << rollno << endl; cout << "Marks obtained in Subject1: " << m1 << endl; cout << "Marks obtained in Subject2: " << m2 << endl; cout << "Marks obtained in Subject3: " << m3 << endl; cout << "Percentage: " << getPercentage() << endl; cout << "Grade obtained: " << getGrade() << endl; } }; int main() { //student object s1 and s2 created in main
  • 4. 4 | P a g e CS-212 Object Oriented Programming //The age, roll no, and marks are ontained from the user by using the class student student s1; student s2; cout << "Enter below the details of the student Ahamed," << endl; s1.getinfo(); cout << "n"; cout << "Enter below the details of the student Musharaf," << endl; s2.getinfo(); cout << "n"; //displaying the percentage and grade of both the students using the created getPercentage and getGrade functions cout << "Ahamed's percentage is: " << s1.getPercentage() << endl; cout << "Musharaf's percentage is: " << s2.getPercentage() << endl; cout << "n"; cout << "Ahamed's grade is: " << s1.getGrade() << endl; cout << "Musharaf's grade is: " << s2.getGrade() << endl; cout << "n"; //Display of summary of both the students cout << "Ahamed's summary: " << endl; s1.putdata(); cout << "n"; cout << "Musharaf's summary: " << endl; s2.putdata(); return 0; }
  • 5. 5 | P a g e CS-212 Object Oriented Programming
  • 6. 6 | P a g e CS-212 Object Oriented Programming Output:
  • 7. 7 | P a g e CS-212 Object Oriented Programming