Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to create a program that will create Objects of different array size

ID: 3792675 • Letter: I

Question

I am trying to create a program that will create Objects of different array sizes.

The main program inputs a charactor and two coordinates. It then attempts to identify what sort of object it needs to return. If it is an O, it will create an array of size one with the number 1 in it. I Cannot change main in any way. I don't know how to create an array and return it as t1. can someome help me?

Thanks

int main(){

Shape *t1, *t2;

cin>>ch >>x >>y;

t1 = Shape :: makeshape(ch, x, y);

}

//I am working on defination of makeshape

Shape *makeShape( char ch, int posx, int posy)}{
      
if(char=='O'){

O array = new O[1];
    return O;
} //or do I need a pointer here?
}

Explanation / Answer

Yup you can return an array . But , you have to do some modification. In the function makeShape , you have specified Shape class object to be the return type. But, you are sending array so you need to change the return type. And, it would effiecient if you send a pointer. Then,one can get dynamic memory . But, answer for your question is yes ; you just need to change the return type of the function.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote