Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( It ' s a c + + code ) Code the following as one cpp file. Don't separate the class, and members functions, and

(It's a c++ code)
Code the following as one cpp file. Don't separate the class, and members functions, and main
program into separate source files as would normally be done.
Define a simple class named SampleClass. It has two public members, both ints, mem 1 and
mem2. It has one public member function, memFunc1. memFunc has one int parameter and
an int return value. memFunc prints a message saying "memFunc1 has been called." It returns
the value passed as a parameter, plus one. No constructor or destructor is required.
Write a main program that defines the following five items.
an object of SampleClass named obj1
an array of SampleClass objects named objarray1 with 100 elements
a dynamically allocated object of SampleClass, choosing whatever pointer name you
want
a dynamically allocated array of 100 SampleClass objects, again using whatever pointer
name you want
a set of 100 dynamically allocated SampleClass objects, using an array of 100 pointers.
Name the pointer array whatever you wish. Use a loop to allocate the objects and don't
worry about initializing them.
Next add:
in part 1, set member mem1 in object obj1 to the value 33. Call the member function
for the object, passing the value 55. On return from the member function, print the
return value.
part 2, set member mem1 from the element with index 10 of the objarray1 array to 34.
Call the member function for the object with index 10, passing the value 55. On return
from the member function, print the return value.
part 3, set member mem 1 in the dynamically allocated object to 35. Call the member
function for the object, passing the value 55. On return from the member function,
print the return value.
part 4, set member mem1 from the element with index 10 of the dynamically allocated bject array to 36. Call the member function for the object with index 10, passing the value 55. On return from the member function, print the return value.
part 5, set the 11th dynamically allocated element (that would be index 10 in the pointer array) member mem1 to value 37. Call the member function for the object associated with the pointer in the pointer array with index 10, passing the value 55. On return from the member function, print the return value.
For example, here is the complete answer for (1):
int rv:
SampleClass objl;
objl.meml=33;
rv= obj1.memFunc1(55) ;
cout rv endl
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What are the main objectives of Inventory ?

Answered: 1 week ago

Question

Explain the various inventory management techniques in detail.

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago