Answered step by step
Verified Expert Solution
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
Its 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 and
mem It has one public member function, memFunc memFunc has one int parameter and
an int return value. memFunc prints a message saying "memFunc 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 obj
an array of SampleClass objects named objarray with elements
a dynamically allocated object of SampleClass, choosing whatever pointer name you
want
a dynamically allocated array of SampleClass objects, again using whatever pointer
name you want
a set of dynamically allocated SampleClass objects, using an array of 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 set member mem in object obj to the value Call the member function
for the object, passing the value On return from the member function, print the
return value.
part set member mem from the element with index of the objarray array to
Call the member function for the object with index passing the value On return
from the member function, print the return value.
part set member mem in the dynamically allocated object to Call the member
function for the object, passing the value On return from the member function,
print the return value.
part set member mem from the element with index of the dynamically allocated bject array to Call the member function for the object with index passing the value On return from the member function, print the return value.
part set the th dynamically allocated element that would be index in the pointer array member mem to value Call the member function for the object associated with the pointer in the pointer array with index passing the value On return from the member function, print the return value.
For example, here is the complete answer for :
int rv:
SampleClass objl;
objl.meml;
rv objmemFunc ;
cout rv endl
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started