Help on assignment

Hi guys, i need help on starting my assignment.
I am supposed to design a program that takes in coordinates of a square, cross
and rectangle. Based on those coordinates, i can sort them according to area(ascending and descending) and sort by the special type which is keyed in during user input.
I can also display the data that was keyed in by the user.
i am required to use polymorphism to code this program.

here is what i have done so

assn2.cpp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include "ShapeTwoD.h"
#include "Cross.h"

using namespace std;


string arrayOfShapes[100];
int counter=0;

void showProgram()
{
      
      cout<<"Welcome to Assn2 program!"<<endl<<
   
      "1)Input sensor data."<<endl<<
      "2)Compute area (for all records)"<<endl<<
      "3)Print shapes report."<<endl<<   		
      "4)Sort shape data."<<endl;
       


}

int main()
{
	string shape,type;
	int choice;	
	ShapeTwoD shape2D;
	Cross cross;
	ShapeTwoD *Cross= &cross;


        //Cross -> setValues(4,5);
	
	do
	{
	showProgram();
	cout<<"Please select your choice :";
	cin>>choice;
	


	switch(choice)
	{

	case 1 : cout<<endl;
		 cout<<"[Input sensor data]"<<endl;
		 cout<<"Please enter name of shape :"<<endl;
		 cin>>shape;
		 shape2D.setName(shape);
		 cout<<"Please enter special type :"<<endl;
		 cin>>type;
		 shape2D.setWarpSpace(type);
		 cout<<shape2D.getName();	
		 if(shape2D.getName()=="Cross"||shape2D.getName()=="cross")
		 {
			cross.setCord();
			//cout<<cross.toString();
			arrayOfShapes[counter]=cross.toString();
			//cout<<cross.toString();
			counter++;
			
			/*for(int i=0;i<counter;i++)
			{
			cout<<arrayOfShapes[i];
			}*/
			//counter++;
			//counter--;
			
			//cout<<Cross->computeArea()<<endl;

            	 }

		 cout<<"Record successfully stored. Going back to main menu...."<<endl;

		 break;


	case 2:  //compute method
		 cout<<"Computation completed!"<<endl;






	}

	}while(choice !=5);



ShapeTwoD.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "ShapeTwoD.h"



void ShapeTwoD::setName(string shapeName)
{

  name=shapeName;


}

string ShapeTwoD::getName()
{

 return name;

}

string ShapeTwoD::toString()
{

 return s;
}

void ShapeTwoD::setValues(int a, int b)
{

 width=a;
 height=b;
}


void ShapeTwoD::setContainsWarpSpace()
{
      string warp;
      if(warp=="WS")
      containsWarpSpace=true;
      else if(warp=="NS")
      containsWarpSpace=false;	
}


bool ShapeTwoD::getContainsWarpSpace()
{

   return containsWarpSpace;
}




void ShapeTwoD::setWarpSpace(string space)
{
 
warpSpace=space;

}

string ShapeTwoD::getWarpSpace()
{

 return warpSpace;
}

double ShapeTwoD::computeArea()
{

 return 0.00;
}
bool ShapeTwoD::isPointInShape(int cordA,int cordB)
{
   xCord=cordA;
   yCord=cordB;

   if(xCord > 5 || yCord > 5)
   return false;
   else
   return true;	
}

bool ShapeTwoD::isPointOnShape(int cordA,int cordB)
{
   xCord=cordA;
   yCord=cordB;


   if(xCord > 10 || yCord <10)
    {

	return false;

    }
	else
{
	return true;
}


}




Cross.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "Cross.h"
void Cross::setCord()
{
   
   for(int i=0;i<12;i++)
   {

	cout<<"Please enter x-cordinate of pt."<<i+1;
	cin>>x;
	cout<<"Please enter y-cordinate of pt."<<i+1;
	cin>>y;

   }

}

double Cross::computeArea()
{
  return (width * height);

}

int Cross::getxCord()
{
  
   return x;
   
  
}


int Cross::getyCord()
{

  return y;

}

string Cross::toString()
{
  string s;
  
  
  int x=getxCord();
  
  int y=getyCord();
  
  
  counter++;
  counter--;
  stringstream convertX;
  stringstream convertY;
  convertX<<x;
  convertY<<y;
  string xResult=convertX.str();
  string yResult=convertY.str();
  s+=xResult;
  s+=","+yResult+",";
  
  return s;
}

bool Cross::isPointOnShape(int cordA,int cordB)
{
 	cordA=getxCord();
	cordB=getyCord();

    if(cordA >3 || cordB>3)
    {
	return true;

    }
    else 
    return false;


}

bool Cross::isPointInShape(int cordA,int cordB)
{
     cordA=getxCord();
     cordB=getyCord();


     if(cordA > 5|| cordB >5)
     {

	return false;

     }
	else
	return true;

}


what i have been doing is that, i have done it in a way that it uses a
string array arrayOfShapes to store the data that was keyed in by the user input and also to store the area that was calculated.
My logic is to use a string stream to separate the values.
then using the methods isPointOnShape and isPointinShape to determine whether the points are on the shape or in the shape. Then i will print them out using a boolean value as a qualifier.
However, the problem is that i am unable to get 12 values of x and y coordinates
from the setCord method in the Cross.cpp. It always gives me 2 instead of 12.
May i know the way of solving this? and is there a way that i can use a class array? i want to try something new.
closed account (4z0M4iN6)
The first thing, what I would like to tell you is:

You should explain the problem at the beginning and not at the end.
I looked at the beginning and saw something, which looked like there would be much work to do and this without any loan.

And there are many listings. Maybe this is only one part: the beginning? For the big end, he would need somebody, who does it?

Coud be, that peopple think so, before they read the end. Maybe they don't read until end?

This could have been a reason, that you didn't get a reply besides me.

Clearner88 wrote:

i am unable to get 12 values of x and y coordinates


1
2
3
4
5
6
7
8
9
10
11
void Cross::setCord()
{
    for(int i=0;i<12;i++)
   {

	cout<<"Please enter x-cordinate of pt."<<i+1;
	cin>>x;
	cout<<"Please enter y-cordinate of pt."<<i+1;
	cin>>y;
   }
}



I'm unable too. Can't imagine, how to get out 12 valueas from one single variable?

Clearner88 wrote:
May i know the way of solving this? and is there a way that i can use a class array?


There are many ways, how to do something.

If you normally use classes for i,j,x,y, then I assume, that you also would like to use a class for an array.

But if you normally use normal variables, then you should also use normal arrays.

Clearner88 wrote:

i want to try something new.

And I'm shure, that this isn't something new. There is no money to earn. A pity, people discovered this already before. And this I can show you, by using also this now discovered and unhidden secret:


1
2
3
4
5
6
7
   for(int i=0;i<12;i++)
   {
	cout<<"Please enter x-cordinate of pt."<<i+1;
	cin>>x[i];
	cout<<"Please enter y-cordinate of pt."<<i+1;
	cin>>y[i];
   }

Last edited on
Sorry for the long story. Thanks for the advice
closed account (4z0M4iN6)
I hope, you find also somewhere how to declare an array.

Or you can also find it here: instead of int x declare int x[12] and don't forget about y.
I hope you realize that this forum is not a place to find people to do your homework for you. Just saying.
closed account (4z0M4iN6)
Ahaanomegas wrote:
I hope you realize that this forum is not a place to find people to do your homework for you. Just saying.

@Clearner88

Now you can see, what Ahhanomegas understood and I think many of the other too besides me. Seems, not many here seem to understand posts.

I would suggest:

1. to read the post until the end
2. then to think, what it means

If somebody want to give an answer, he should take care, that he also understands the question.

And it wasn't a homework.

I will explain:

Clearner88 asked; x,y?
I answered: x[i], y[i]!


Nobody should say, this would be a homework.
Last edited on
@cLearner 88
r u frm sim-ouw, ft/pt? whats ur name. y nt use struct
@Ahaanomegas
i am not asking you guys to help me do my work.
i am just asking for advice as in how to start it and
how do i get 12 values of x and y coordinates from a method.
As everything is messed up right now. Sorry for the confusion

@dadabe
Thanks for the defense


closed account (4z0M4iN6)
@Clearner88

You're welcome.

Maybe you can help also me.
I thougt about defensing users.
I thought, if a user asks for help and needs only an idea, that other ones, shouldn't dump their often not so useful listings into such a post.
And I had a long discussion about this.
But now I've seen, sometimes it would be neccessary to show an example. This would be neccessary, I don't know exactly, maybe only in one case out of 100, maybe also in some more. But now it looks like I've lost this discussion.

I will show you such a case:

http://cplusplus.com/forum/beginner/71033/

I know, whether somebody needs an idea or an example. But how can others know about this? They want to help and do what they can. But nobody can't do, more than he can.
Last edited on
@CLearner88, @dadabe: It wouldn't matter. Everyone that sees anything about assignments get uptight and think all of them should be deleted and the users banned. I love how this site is supposed to be here to help everyone and yet most the guys get annoyed when the ones that need the help most ask for it. I mean, who needs more C++ guidance and help than a student in programming courses? :-/
Last edited on by closed account z6A9GNh0
closed account (4z0M4iN6)
@CLearner88

You are right, they shouldn't be annoyed. But it would not be a bad idea, that they also could learn something. They could learn, also to show the idea. Now I'd like to know about the outcome. I showed my example, and they didn't look at it, maybe they didn't understand it, because they didn't know the idea. Now I gave them the idea too.

An idea can be grasped immediatly. Once it's read, its in the mind. This can't be hindered. And when somebody has the idea, he can understand the example. Maybe he chooses first to implement the solution and look after at the example. Everybody may do as he likes.

What everyone could learn, who wants to help, is also to show the idea.


Last edited on
Topic archived. No new replies allowed.