No: 01
1.
Experiment
vision:
To
write a program on the concept of array of object.
2.
OBJECTIVE:
Program
to implement an array of object in C++.
3.1
THEORY:
An
array is a secondary variable that store similar data item in a
continuous memory location. We can create array of built in data
type. i.e. i
i.e.
int X[10];
float
Z[2];
char
Y[15];
The
above example shows the array of built in data type.
Array
of Object is a collection of objects of same class. Elements of array
are accessed by array name followed by index.
3.2
PROGRAM:
1)
Following
is an example which makes use of array of object to returns
information about five students:
#include
<iostream>
using
namespace std;
class
student
{
char
name[30];
int
age;
float
per;
public:
void
getdata();
void
display();
};
void
student::getdata()
{
cout<<"Enter
information about student:";
cin>>name>>age>>per;
}
void
student::display()
{
cout<<"\nname="<<name;
cout<<"\tage="<<age;
cout<<"\tper="<<per;
}
int
main()
{
student
s[5];
for(int
i=0;i<=4;i++)
{
s[i].getdata();
}
for(int
j=0;j<=4;j++)
{
s[j].display();
}
return
0;
}
3.3.
OUTPUT:
4.
conclusion:
Thus
a
C++ program Programs by using array of objecthas
been executed successfully.
5.
PRECAUTIONS:
-
Avoid wrong keywords
-
Check whether all brackets are closed properly or not.
-
Take desired output.
-
In case of abnormal results, Contact the teacher/instructor, repeat the experiment, and check the algorithm and program.
6.
REMARK:
Array
of object is the concept is used for printing the values of number
objects by writing the methods in class once at a time.
7.
Discussion
Questions:
1)
what
are objects? How are they created?
____________________________________________________________________________________________________________________________________________________________
2)
What is class? How to declare it.
____________________________________________________________________________________________________________________________________________________________
3)
What are the different access specifiers?
____________________________________________________________________________________________________________________________________________________________
4)
What is the use of dot operator?
____________________________________________________________________________________________________________________________________________________________
No comments:
Post a Comment