Could someone help me in converting this to C++ language?
Question Get Answer

Could someone help me in converting this to C++ language? all files are compiled together.

main.c

#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>


#include "shape.h"


int main()

{

char cmd;

int index, count;

float xIn, yIn, angle;

typedef enum {Tri, Rec, None} modeType;

modeType mode = None;

do

{

cmd=getchar();

cmd=toupper(cmd);

switch (cmd)

{

case 'S': // We have a mode select command


cmd=getchar();

cmd=toupper(cmd);

switch(cmd)

{

case 'T':

mode=Tri;

break;

case 'R':

mode=Rec;

break;

default:

printf("Undefined geometry type: %c\n",cmd);

}

break;

case 'P': // We have a point set command

count=scanf("%d %f %f", &index, &xIn, &yIn);

if (count==3)

{

if (mode==Tri)

triSet(index, xIn, yIn);

else

rectSet(index, xIn, yIn);

}

else

printf("Wrong arguments for Point set command\n");

break;

case 'T': // We have a translate command

cmd=getchar();

cmd=toupper(cmd);

switch (cmd)

{

case 'R':

count=scanf("%f %f", &xIn, &yIn);

if (count != 2) count=0;

break;

case 'X':

count=scanf("%f", &xIn);

yIn=0.0;

if (count != 1) count=0;

break;

case 'Y':

xIn=0.0;

count=scanf("%f", &yIn);

if (count != 1) count=0;

break;

default:

count=0;

}

if (count != 0)

{

if (mode==Tri)

triTranslate(xIn, yIn);

else

rectTranslate(xIn, yIn);

}

else 

printf("Error in translate command: no translation performed.\n");

break;

case 'R': // We have a rotate command

cmd=getchar();

cmd=toupper(cmd);

switch (cmd)

{

case 'A': // Rotation about an arbitrary point

count=scanf("%f %f %f", &xIn, &yIn, &angle);

if (count != 3) count=0;

break;

case 'O': // Rotation about the origin

xIn=0.0;

yIn=0.0;

count=scanf("%f",&angle);

if (count != 1) count=0;

break;

case 'C': // Rotation about the centre of the current figure

count=1;

if (mode==Tri)

{

xIn=triGetCX();

yIn=triGetCY();

}

else

{

xIn=rectGetCX();

yIn=rectGetCY();

}

default: // Assume rotation about one of the vertices

if (isdigit(cmd))

{

index=cmd-48; // Convert the ASCII character to the corresponding integer

count=scanf("%f",&angle);

if (count==1)

{

if (mode==Tri)

{

if (index<0 || index >2)

count=0;

else

{

xIn=triGetX(index);

yIn=triGetY(index);

}

}

else

{

if (index<0 || index >3)

count=0;

else

{

xIn=rectGetX(index);

yIn=rectGetY(index);

}

}

}

else 

count=0;

}

else

{

count=0;

}

}

if (count!=0)

{

if (mode==Tri)

triRotate(xIn, yIn, angle);

else

rectRotate(xIn, yIn, angle);

}

else

printf("Error in rotate command: no rotation performed.\n");

break;

case 'O': // Output current figure

if (mode==Tri)

triReport();

else

rectReport();

break;

case 'Q': // Quit

break;

default : // Some thing we didn't expect

printf("Error: Bad Command %c\n", cmd);

}

while ((getchar()) != '\n'); // Flush the input buffer after processing each command

} while (cmd!='Q');

return 0;


}


shape.c


#include <stdio.h>

#include <math.h>


#include "shape.h"


static triangle T;

static rectangle R;


point pointSet(float x, float y) // create point (x,y)

{

point Temp;

Temp.x=x;

Temp.y=y;

return Temp;

}


point pointTranslate(point P, float x, float y) // translate an input point by (x,y)

{

point Temp;

Temp.x=P.x+x;

Temp.y=P.y+y;

return Temp;

}

point pointRotate(point P, float x, float y, float angle) // rotate an input point by angle degrees about (x,y)

{

point Temp;

angle =M_PI*angle/180.0;

Temp.x=(cos(angle)*(P.x-x)-sin(angle)*(P.y-y))+x;

Temp.y=(sin(angle)*(P.x-x)+cos(angle)*(P.y-y))+y;

return Temp;

}


void pointReport(int index, point P) // report the x and y values of an input point

{

printf("Vertex %d: x=%f y=%f\n", index, P.x, P.y);

return;

}


void triSet(int index, float x, float y) // set the value of a vertex

{

if (index<0 || index>2) // if this is not a valid vertex

{

printf("Bad index value: %d\n",index);

return;

}

T.P[index]=pointSet(x, y);

return;

}


void triTranslate(float x, float y) // move the triangle by (x,y)

{

int i;

for (i=0; i<3; i++)

{

T.P[i]=pointTranslate(T.P[i], x, y);

}

return;

}


void triRotate(float x, float y, float angle) // rotate the triangle by angle degrees around (x,y)

{

int i;

triangle Temp;

for (i=0; i<3; i++)

{

Temp.P[i]=pointRotate(T.P[i], x, y, angle);

}

for (i=0; i<3; i++)

{

T.P[i]=Temp.P[i];

}

return;

}


void triReport(void) // report the current triangle points

{

int i;

printf("Triangle Output:\n");

for (i=0; i<3; i++)

{

pointReport(i, T.P[i]);

}

return;

}

float triGetX(int index) // retrieve the x-point of a specific vertex

{

return T.P[index].x;

}


float triGetY(int index) // retrieve the y-point of a specific vertex

{

return T.P[index].y;

}


float triGetCX(void) // retrieve the x-point of the centre of the triangle

{

float cx=0;

int i;

for (i=0; i<3; i++)

cx+=T.P[i].x;

return cx/3.0;

}


float triGetCY(void) // retrieve the y-ccordinate of the centre of the triangle

{

float cy=0;

int i;

for (i=0; i<3; i++)

cy+=T.P[i].y;

return cy/3.0;

}


void rectSet(int index, float x, float y) // set the value of a vertex

{

if (index<0 || index>3) // if this is not a valid vertex

{

printf("Bad index value: %d\n",index);

return;

} R.P[index]=pointSet(x, y);

return;

}


void rectTranslate(float x, float y) // move the rectangle by (x,y)

{

int i;

for (i=0; i<4; i++)

{

R.P[i]=pointTranslate(R.P[i], x, y);

}

return;

}


void rectRotate(float x, float y, float angle) // rotate the rectangle by angle degrees around (x,y

{

int i;

rectangle Temp;

for (i=0; i<4; i++)

{

Temp.P[i]=pointRotate(R.P[i], x, y, angle);

}

for (i=0; i<4; i++)

{

R.P[i]=Temp.P[i];

}

return;

}


void rectReport(void) // report the current rectiangle points

{

int i;

printf("Rectangle Output:\n");

for (i=0; i<4; i++)

{

pointReport(i, R.P[i]);

}

return;

}

float rectGetX(int index) // retrieve the x-point of a specific vertex

{

return R.P[index].x;

}


float rectGetY(int index) // retrieve the y-point of a specific vertex

{

return R.P[index].y;

}


float rectGetCX(void) // retrieve the x-point of the centre of the triangle

{

float cx=0;

int i;

for (i=0; i<4; i++)

cx+=R.P[i].x;

return cx/4.0;

}


float rectGetCY(void) // retrieve the y-point of the centre of the triangle

{

float cy=0;

int i;

for (i=0; i<4; i++)

cy+=R.P[i].y;

return cy/4.0;

}


shape.h


typedef struct

{

float x;

float y;

} point;


typedef struct{

point P[3];

} triangle;


typedef struct{

point P[4];

} rectangle;


point pointSet(float x, float y);

point pointTranslate(point P, float x, float y);

point pointRotate(point P, float x, float y, float angle);

void pointReport(int index, point P);


void triSet(int index, float x, float y);

void triTranslate(float x, float y);

void triRotate(float x, float y, float angle);

void triReport(void);

float triGetX(int index);

float triGetY(int index);

float triGetCX(void);

float triGetCY(void);


void rectSet(int index, float x, float y);

void rectTranslate(float x, float y);

void rectRotate(float x, float y, float angle);

void rectReport(void);

float rectGetX(int index);

float rectGetY(int index);

float rectGetCX(void);

float rectGetCY(void);

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 Computer Science tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes