Array of objects, C/C++ Programming

Assignment Help:

Array of Objects:

The objects can be declared just like a structure or even a primary data type.  Array of objects may be required to work with large set of data.   When the data is very few objects without array can be used. The declaration of array of object is a follows.

int x; int x[10];  The integer x can store only one data at a time where as array integer x

can store 10 data at time because the size is defined as 10.  This is equivalent to declaring 10 individual integers.

 

class employee

{           char name [30]; float age; public:

void getdata(void);

void putdata(void);

};

 

The class employee has two data members and two functions members.  Earlier an object was produced using as shown

employee manager,foreman,worker;

The three objects are created with different names.  The class employee can created as array of objects as shown below.

employee managers[3]; employee foremen[15]; employee workers[75];

 

 

There are 93 objects of class employee.   There grouped into three manager, foreman, worker.  This is literally means the object store information of 3 managers, 15 foremen, and 75 workers.   Thus array of object will permit group the functionality.   The array element can be accessed using dot operator, just accessing member in the structure.

manager[i].getdata( );

 

The given program will give better understanding of array of objects class employee

{char name[25]; float age; public:

void getdata(void)

{cout<<"Enter Name: "<<"\n";

cin>>name;

cout<<"Enter Age: "<<"\n";

cin>>age;

}

void putdata(void)

{cout<<"Name is "<

cout<<"Age is "<

}

};

 

int main()

{clrscr();

int i;

employee staff[25];

for (i=0;i<25;i++)

{staff[i].getdata();

}

for (i=0;i<25;i++)

{staff[i].putdata();

}

 

cout<<"\n";

getch();

return 0;

}

 

 


Related Discussions:- Array of objects

What is virtual class and friend class, Friend classes are used when two or...

Friend classes are used when two or more classes are designed to work together and require access to each other's execution in ways that the rest of the world shouldn't be permitte

Files, redirection in c++

redirection in c++

C, how to learn programming skills

how to learn programming skills

C program for count the no which you want , # include stdio.h> # include...

# include stdio.h> # include string.h> # include conio.h> void main() {           int i=0,j=0,b=0,count=0;           int a[100];           for(i=0;i

Identifier and constant, What are  Id e n t i f ie rs a n d C o...

What are  Id e n t i f ie rs a n d C o n s t a n ts in C++? Id e n t i f ie r a n d C o n s t a n t : I d e n t i f ie r

Applied scientific computing in c++, i have a project that is due this Wedn...

i have a project that is due this Wednesday and i was wondering if i can get help in doing it?

Padovan string, a padovan string p(n) for a natural number n is defined a...

a padovan string p(n) for a natural number n is defined as p(0)=''x'' p(1)=''y'' p(2)=''z'' p(n)=p(n-2)+p(n-3),n>2

C++ Assignment Help me , Write a c++ program that contain the following fun...

Write a c++ program that contain the following functions : 1) Function Quality_Point that takes one int argument (student_average) and return ‘A’ if the student_average between 90-

Super ansii prgm, Ask quIn the Byteland country a string "s" is said to sup...

Ask quIn the Byteland country a string "s" is said to super ascii string if and only if count of each charecter in the string is equal to its ascci value in the byteland country as

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd