Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise A: The objective of this exercise is to help you in understanding how C + + objects are shown on a memory diagram, and

Exercise A:
The objective of this exercise is to help you in understanding how C++ objects are shown on a memory
diagram, and how a member function of a class uses the this pointer to access an object associated with a
particular function call.
What to Do:
2
Download files cplx.cpp, cplx.h, and lab4ExA.cpp from the D2L and draw AR diagrams for: point
one and point two.
For this exercise you just need to draw the diagrams. However, if you want to compile and run it from
command line, you should have all of the given files in the same directory and from that directory you should
use the following command to compile and create an executable:
g++-Wall cplx.cpp lab4ExA.cpp
Please notice that you shouldnt have the header file name(s) in this command.
What to Submit:
Submit your diagram as part of your lab report.
cplx.h:
#ifndef cplx_h
#define cplx_h
class Cplx {
public:
Cplx(): realM(-99), imagM(-99){}
Cplx (double r, double i);
double getRealPart () const;
double getImaginaryPart () const;
void setRealPart(double arg);
void setImaginaryPart(double arg);
Cplx add(const Cplx& other)const;
Cplx subtract(const Cplx* other)const;
private:
double realM;
double imagM;
};
#endif /* cplx_h */
cplx.cpp:
#include "cplx.h"
Cplx::Cplx(double real , double imag ): realM(real), imagM(imag){
// point one
}
double Cplx::getRealPart() const {
return realM;
}
double Cplx::getImaginaryPart() const {
return imagM;
}
void Cplx::setRealPart(double arg){
realM = arg;
}
void Cplx::setImaginaryPart(double arg){
imagM = arg;
// point two
}
Lab4ExA.cpp:
#include "cplx.h"
void global_print(const Cplx& n);
int main(void)
{
Cplx num1;
num1.setRealPart(666);
Cplx num2(34,5);
num1.setImaginaryPart(500);
return 0;
}
I included the AR diagram I made, please tell me if it's corect or not.Point 1:
AR
main
main
Point2:
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_2

Step: 3

blur-text-image_3

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

=+3. What are market presence strategies, and which can you name?

Answered: 1 week ago