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

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

Program of sorting algorithms , The program sorting.cpp contains a main f...

The program sorting.cpp contains a main function for testing the operation of several sort algorithms over various data sizes and data set organisations. The program understands

String program, Write a C++ program which does the following: 1. Asks th...

Write a C++ program which does the following: 1. Asks the user to enter the following text "Four score and seven years ago there was a man named Joey Bagadonuts." 2. Save thi

Area under curve, Write a program to find the area under the curve y = f(x)...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b.

Padovan string, A Padovan string P(n) for a natural number n is defined as:...

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

Using nested if statement, write a program in c/C++ using nested if stateme...

write a program in c/C++ using nested if statement for calculating the average marks and grades of 5 subjects

C++ coursework programming for engineering, Hi there I am looking for hel...

Hi there I am looking for help with c++ coursework. Could you please provide me with email address to email a copy of it. Thanks

C++ and matlab, ">http://www.ee.nmt.edu/~erives/289_F12/EE289_Takehome_2.p...

">http://www.ee.nmt.edu/~erives/289_F12/EE289_Takehome_2.pdf http://www.ee.nmt.edu/~erives/289_F12/Takehome2_maze.GIF

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