Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pointers.h code #ifndef POINTERS_H #define POINTERS_H #include using namespace std; class Pointers { public: Pointers(){ a = 5; b = NULL; c = 10; }

Pointers.h code

#ifndef POINTERS_H #define POINTERS_H

#include

using namespace std;

class Pointers { public: Pointers(){ a = 5; b = NULL; c = 10; } Pointers(int a, int* b){ this->a = a; this->b = b; c = 0; } int* getA(){ return &a; } int* getB() const{ return b; } int getC() const{ return c; } void setB(int* b){ this->b = b; } void setC(){ c = *b; } private: int a; int* b; int c; }; #endif

manip.h code

#ifndef MANIP_H #define MANIP_H

// Author: Fill in your name // Source File: manip.h // Description: A set of functions where you should manipulate // the passed parameters to change the object in a specific way, // so that Pointers_test.h passes all tests.

#include "Pointers.h"

// A little something to get you going void manip1(Pointers* p){ *(p->getA()) = 10; }

void manip2(Pointers* p){ // TODO: Fill me in *(p->getA()) = 45; }

void manip3(Pointers* p){ // TODO: Fill me in }

void manip4(Pointers* p, int* other){ // TODO: Fill me in }

void manip5(Pointers* p, int* other){ // TODO: Fill me in }

void manip6(Pointers* p){ // TODO: Fill me in }

void manip7(Pointers* p){ // TODO: Fill me in }

void manip8(Pointers* p){ // TODO: Fill me in }

void manip9(Pointers* p, int* other){ // TODO: Fill me in }

void manip10(Pointers* p){ // TODO: Fill me in }

#endif

Sandbox file used to test the manip code

#include "Pointers.h" #include "manip.h" #include #include

using namespace std;

int main() { // maninp1 Pointers a; manip1(&a); cout << "maninp1:" << endl; cout << (*(a.getA())) << "\t== 10 " << endl; // maninp1 2 int number = 56; Pointers b(number, &number); manip2(&b); cout << "maninp2:" << endl; cout << (*(b.getB())) << "\t== 45" << endl; // maninp1 3 number = rand() % 1000; int number2 = 4;

Pointers c(number, &number2); manip3(&c); cout << "maninp3:" << endl; cout << (*(c.getB())) << "\t== " << number << endl;

number2 = 4; Pointers d; manip4(&d, &number2); cout << "maninp4:" << endl; cout << d.getB() << "\t== " << &number2 << endl; cout << (d.getB() == &number2) << "\t== 1" << endl; number2 = 4; Pointers e(0, &number2); manip5(&e, &number2); cout << "maninp5:" << endl; cout << e.getC() << "\t== " << 45 << endl; int numbers[] = {5,6,7,8}; Pointers f(0, numbers); manip6(&f); cout << "maninp6:" << endl; cout << numbers[2] << "\t== " << 10 << endl;

int* number3 = new int; Pointers g(0, number3); manip7(&g); cout << "maninp7:" << endl; cout << *number3 << "\t== " << 15 << endl; delete number3; Pointers h; manip8(&h); cout << "maninp8:" << endl; cout << h.getC() << "\t== " << 199 << endl;

int* number4 = new int; Pointers* i = new Pointers(); manip9(i, number4); cout << "maninp9:" << endl; cout << i->getB() << "\t== " << number4 << endl; delete number4; delete i;

Pointers* j = new Pointers[10]; manip10(j); cout << "maninp10:" << endl; cout << j[5].getC() << "\t== " << 199 << endl; delete[] j;

return 0; }

Fill in the manip functions in the manip file to match this output:

maninp1: 10 = 10 maninp2: 45 = 45 maninp3: 383 = 383 maninp4: 0x7fff8072b6fc = 0x7fff8072b6fc 1 == 1 maninp5: 45 = 45 maninp6: 10 = 10 maninp7: 15 = 15 maninp8: 199 = 199 maninp9: 0xbe9c20 = 0xbe9c20 maninp10: 199 = 199

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

Master The Art Of Data Storytelling With Visualizations

Authors: Alexander N Donovan

1st Edition

B0CNMD9QRD, 979-8867864248

More Books

Students also viewed these Databases questions

Question

1. Why do we trust one type of information more than another?

Answered: 1 week ago

Question

Expansionary monetary policy is monetary policy A . tight B . loose

Answered: 1 week ago