0% found this document useful (0 votes)
56 views4 pages

Experiment No.3: Class and Object

This document describes a C++ program that defines a Student class with data members like name, roll number, etc. and member functions to get and display student details. The program creates an object of the Student class, uses the getStudentData() function to input details from the keyboard, and the DisplayStudentData() function to output the details to the screen. The program demonstrates the basics of classes and objects in C++ for modeling real-world entities like students.

Uploaded by

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

Experiment No.3: Class and Object

This document describes a C++ program that defines a Student class with data members like name, roll number, etc. and member functions to get and display student details. The program creates an object of the Student class, uses the getStudentData() function to input details from the keyboard, and the DisplayStudentData() function to output the details to the screen. The program demonstrates the basics of classes and objects in C++ for modeling real-world entities like students.

Uploaded by

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

Name: Ashutosh Dhande

Rollno : 19EE1135
Batch: A2

Experiment No.3 : Class and Object


1. Aim: Write a program to read the class object of Student such as Rollno,Name ,Class,
Division and Marks. Create functions inside class to take input from the keyboard using
getStudentData() and DisplayStudentData() for displaying the student details on the screen 2.
Objectives:
• To apply fundamental programming constructs and understand the C++
Programming.
• Understand basics of Object Oriented programming To solve the real
world scenarios using top down approach.
3. Outcomes:
• Understand fundamental features of an object-oriented language: object classes
and interfaces, exceptions and libraries of object collections
• Understand how to model the real world scenario using classes and object.

4. Hardware / Software Required : Unbuntu, C++.

5. Theory: A class in C++ is the building block, that leads to Object-Oriented programming.
It is a user-defined data type, which holds its own data members and member functions,
which can be accessed and used by creating an instance of that class. A C++ class is like a
blueprint for an object.
• A Class is a user defined data-type which has data members and member functions.
• Data members are the data variables and member functions are the functions used to
manipulate these variables and together these data members and member functions
defines the properties and behavior of the objects in a Class.
• In the above example of class Car, the data member will be speed limit, mileage etc
and member functions can be apply brakes, increase speed etc.
An Object is an instance of a Class. When a class is defined, no memory is allocated but when it
is instantiated (i.e. an object is created) memory is allocated.
Syntax:
A class is defined in C++ using keyword class followed by the name of class. The body of class
is defined inside the curly brackets and terminated by a semicolon at the end.
Class ClassName
{ Acess specifier: // can be private,public or protected
Data members; // variable to be used
Member Function(){} //Method to acess data members
}; // class name ends with a semicolon

In this program, the object of class Student is used to access the methods getStudentData()
and DisplayStudentData() of this class.
Name: Ashutosh Dhande
Rollno : 19EE1135
Batch: A2

6. Algorithm 1. Start.
2. Declare a class named Student.
3. Initialize the required variables.
4. Declare a method getStudentData() and get value of Rollno,Name ,Class, Division and
Marks from the user.
5. Declare a method DisplayStudentData() to displaying the student details on the screen
6. Declare main() and create object of class Students. And access the methods with the help
of object.
7. Display the details.
8. Stop.

Program:
#include <iostream>

using namespace std;

class student
{ char student_name[30];
char roll_no[10];
char branch[20];
int year;
char divi[5];
public:
void getdetails();
void putdetails();
};
void student::getdetails(void)
{ cout<<"\nEnter the name: ";
cin >>student_name ;
cout<<"\nEnter the rollno: ";
Name: Ashutosh Dhande
Rollno : 19EE1135
Batch: A2

cin>>roll_no;
cout<<"\n Enter the branch name:";
cin>>branch;
cout<<"\nEnter division: ";
cin>>divi;
cout<<"\n Enter the year:";
cin >>year ;
}

void student::putdetails(void) {
cout<<"\nSTUDENT DETAILS........";
cout<<"\nNAME:"<<student_name;
cout<<"\nROLL NO.:"<<roll_no;
cout<<"\nBRANCH NAME:"<<branch;
cout<<"\nDIVISION:"<<divi;
cout<<"\nYEAR:"<<year;
}
int main()
{ student std;
std.getdetails();
std.putdetails();
return 0;
}
Output:
Name: Ashutosh Dhande
Rollno : 19EE1135
Batch: A2

7. Conclusion:
After performing this experiment we are able to create a class and object. The classes are
interacting with each other by accessing the methods and members of class using different
objects.

You might also like