C/C++ :: Structure Representing Point In XY-plane
Mar 18, 2015
We are supposed to create a point structure that can be used to represent a point in the xy-plane. Then, write a menu-driven C++ program that uses variables of type point to perform a variety of tasks involving points in the xy plane, including slope, distance, midpoint, equation of a line passing through points, and colinearity. One of the functions we are to create is simply for reading in the user-input in the following form "(x,y)" with the user entering the parentheses and comma. We are to create two functions that translate back and forth between this format and what the assignment calls "one point variable."
I'm confused how I'm supposed to take the user entering, say "(1,4)" and reading that into an x and y, and then comparing it against another set of points. I'm guessing I read them in as a, b, c, d, but I'm not sure what this has to do with a structure.
View 1 Replies
ADVERTISEMENT
Mar 25, 2013
I'm following this example on finding the intersection point between a plane and a line. (it's about three quarters down) [URL] .....
However this seems to only show how to solve u.
1. I don't understand what u is.
2. How do I find out the intersection point, in terms of (x, y, z)?
View 4 Replies
View Related
Mar 27, 2014
Suppose, I have point_c, line_c and block_c three classes:
class point_c {
public:
double x, y;
};
class line_c {
public:
vector<point_c> Pt;
[Code] ....
As you can see, lines are composed of many points, and blocks are composed of lines and points. And I defined some member functions, so that I can add points or lines as required by line and block.
But, here comes the problem, if I use line.insertPoints(), or block.insertPoints(), the points will be stored in line or block. That is not what I want.
I want have a single place to store all points, a single place to store all lines, and a single place to store all blocks.
Then I guess I need some global variables
vector<point_c> Pt;
vector<line_c> Ln;
vector<block_c> Bk;
And I should change the classes into:
class point_c {
public:
double x, y;
};
class line_c {
public:
vector<size_t> PtIndex;
[Code] .....
in this way, the member functions will create the real entities into the global vector and set an index pointing to that entity. But this approach just make me feel it is not OOP anymore. when people using these classes, they got be careful about the global variables.
View 7 Replies
View Related
Apr 10, 2013
I am having trouble of exactly how "class" works. I dont know what the difference between set and get is. I have this code:
#include <iostream>
#include <cmath>
using namespace std;
class Point {
private:
double px;
double py;
[Code] .....
How to get void Triangle::setBottomLeftX(const double x) to work.
Implement the get and set member functions for the class Triangle. Use the appropriate class attributes of the class Triangle.
a. The location of the bottom left vertex is stored in the member attribute blPoint.
b. The top left vertex can be computed from blPoint and the height.
c. The bottom right vertex can be computed from blPoint and the length.
View 19 Replies
View Related
Dec 24, 2013
I'm trying to make a space shooter and I want to make the code very reusable. So far I've been making a bunch of objects with multiple inheritance like this:
entity: anything which can be drawn, has a position and an orientation
solid: any entity which can collide with something else
mobile: any entity which can move
spriteEntity : an entity drawn using a sprite
vertexEntity : an entity drawn out of vertexes
The entity class has the virtual method draw, which gets defined by either spriteEntity or vertexEntity. mobile and solid virtually inherit from the entity class.
Then I could create a projectile class which inherits from solid and mobile but adds methods to damage stuff it collides with, and multiple subclasses which inherit from both projectile and spriteEntity... But I'm not sure if it's a good idea to go this deep in multiple inheritance for game objects. I know MI has a bad reputation.
I know that some objects of the game will be sprites and some will be vertexes, and I also know there will be stuff which collides and doesn't move... Or should I make the mobile class a subtype of solid?
View 6 Replies
View Related
Apr 6, 2013
how to use 3 variables to represent a rectangle in a grid instead of using 4. The traditional way is to use (x,y) (x2,y2). I propose using (x,l,h).In the traditional way as you probably know, (x,y) is the left op most corner, and (x2,y2) is the bottom right most corner. In the way I am proposing X is the left side, l is the length of the top side, and also the length of the bottom. 'h' is the height of the left and right. I think it's obvious how these three can define a rectangle same as the four.
View 2 Replies
View Related
Mar 24, 2013
Create a class representing project activities. In this class include all the required data members and member functions. Each activity should have a record of activity duration, calculated early start, early finish, late start, late finish, free float, and total float. Each activity may or may not maintain a list of its successors and predecessors. Provide your design in UML and implement it in C++ using an interface head file and an implementation source file. I do not understand classes or UML designs.
View 2 Replies
View Related
Nov 3, 2013
I have been working on some C++ code that doesn't seem to be going right. I'm wanting it to read a (three-digit) integer representing the value to be encrypted, a (one-digit) integer representing the encryption key, encrypt the value and print the encrypted value. The encrypting method used is that each digit in the given number is replaced by ((the sum of that digit plus key) modulo 10) then the first and last “encrypted” digits are swapped.
For example, if the number entered was 216 and the key given was 7, after applying the encryption procedure described the first digit (2) would become 9, the middle digit (1) would become 8 and the last digit (6) would become 3. The first and last encrypted digits are then swapped. The program displays the encrypted number: that is 389 in this case.
#include <iostream>
using namespace std;
int main() {
int isolateDigits();
int replaceDigits();
int swapDigit1withDigit3();
[Code] ....
View 1 Replies
View Related
Sep 24, 2013
So basically I have an array of hex numbers representing a binary number. Each binary number is 1/5th layer of the over all font.
For example... the letter A
........ B00000000 0x00
.****... B01111000 0x78
...*.*.. B00010100 0x14
...*..*. B00010010 0x12
...*.*.. B00010100 0x14
.****... B01111000 0x78
........ B00000000 0x00
As you can see each HEX number is a layer in the font which consists of in the above example 7 layers.
Now what I would like to do is create a C++ program, so I can visualize a HEX font array that I got off the internet.
#include <iostream>
using namespace std;
const char font[][5] = {
{0x00,0x00,0x00,0x00,0x00}, // 0x20 32
{0x00,0x00,0x6f,0x00,0x00}, // ! 0x21 33
{0x00,0x07,0x00,0x07,0x00}, // " 0x22 34
{0x14,0x7f,0x14,0x7f,0x14}, // # 0x23 35
[Code]...
Basically I am asking two things. How can I make this display the correct representing letter in the array when a user inputs his own text.
And secondly, how can I output the HEX numbers that is in the array as a binary number.
View 1 Replies
View Related
Sep 18, 2013
How to code the following:
I have two random numbers which are generated and are related to each other (representing x and y co-ordinate). These random numbers are generated within a specified range: (-range, +range).
I want to categorize these values in a (2-dimensional) grid. The grid size is not definite and so can be varied by the user would be in the order of 400 x 400. (e.g., think CCD detector). For each random number pair (x, y) I want to store a hit (a plus one) in the corresponding grid reference.
In the order of 500,000 related random numbers (x and y) are to be generated and the position recorded according to grid reference. So code needs to be fast.
View 8 Replies
View Related
Jun 26, 2013
I have one code that use MPI broadcast and I want to change it into Asynchronous Point to Point communication. I am newbie in Parallel programming. Looking for implementation of one simple same program in broadcast and P2P ?
View 6 Replies
View Related
Aug 27, 2013
I am trying to run a programme implementing a function with structures in c... which is:
#include<stdio.h>
#include<conio.h>
struct store {
char name[20];
float price;
int quantity;
[Code] .....
View 1 Replies
View Related
Dec 7, 2014
Why doesn't this compile?
struct hi(){
void other();
}histructure;
void hi::other(){
std::cout << "Hi!" << std::endl;
[Code] ....
Makes no sense the structure is written before the structure member function is called so why is there compile errors ??...
View 3 Replies
View Related
Oct 7, 2014
Is it possible to assign a value to structure member inside the structure.like.....
struct control{
char tbi:2 =0;
char res:1 =0;
};
View 6 Replies
View Related
Mar 17, 2013
how I can create a structure that pointing to another different structure. And also passing structure to function.
View 3 Replies
View Related
Jan 3, 2015
I don't know why this doesn't work. It doesn't return any errors, but it does the polynomial equation wrong. I tried using "^" instead of "pow" and it still does it wrong. I'm getting results like "-897123897" instead of "3". This is the code:
Code:
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
[code]....
View 4 Replies
View Related
May 14, 2013
I am reading about positive and negative infinity in c++ and i am trying to implement them in a fixed point math arthimethic implementation
I can see that max of a int will be equal to std::numeric_limits<int>::max();
and min value of the int will be equal to std::numeric_limits<int>::min();
in c++
Here as i am defining the int max and int min manually in my fixed point math implementation, my doubt is
int min = -int max; or int min = -int max -1; ?
View 1 Replies
View Related
Mar 16, 2014
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
float i;
i=0.7;
[Code] ....
If i do run the above program in turbo C/C++ complier, it outputs "h". But,if i change the code as i=0.6 and if (i<0.6), it outputs "w". Even if i change it to i=0.8 and if(i<0.8), then also it outputs "w".
View 4 Replies
View Related
May 8, 2014
Code:
#include<stdio.h>
#include<conio.h>
float square(float);
void main() { clrscr();
float a,b;
printf("ENter a Number");
scanf("%f",&a);
[Code] ....
In the above program, I am calculating the square of float number. But sometimes the number is entered as NAN and sometimes Output is NAN. What is NAN? I am entering floating point number, then y NAN is entered?
SEE the Image attached for the OUTPUT.
View 2 Replies
View Related
Oct 9, 2013
I have been writing a fixed point library the would handle fixed point numbers with an 8:24 whole/fraction ratio. This has been working quite well but since I have a 24 bit fractional part, it should be able to store 2^(-24).
Code:
long long fraction_part = 0;
long long divisor = 1;
while(*string) {
fraction_part *= 10;
fraction_part += *string - '0';
divisor *= 10;
string++;
}
fraction_part <<= 24;
fraction_part /= divisor;
The issue here is that since the smallest possible fraction is 2^(-24) the divisor could end up needing more than 64 bits and so won't work. I'm not quite sure how else I could do this.
View 7 Replies
View Related
Oct 15, 2014
I have to create dynamic array, where each element of it points to some value. I know how to create dynamic array
Code: array_record * record_1 = (array_record*)malloc( (group!/(2!(group!-2)!)) *sizeof(array_record));
But i don't know how i create this case. for example what i want if array elements are:
Code:
index value value
0 01 -> 345
1 02 -> 457
2 03 -> 689
3 21 -> 634
so if i have value somewhere 01 match with 01 in this array it display 345. how i can implement it?
View 1 Replies
View Related
Sep 27, 2014
I'm wondering about the point of pointers to functions. When is it used?I saw the below example. It doesn't make sense to me. I mean we can easily write code that does the same without having to use pointers.
Code:
#include <stdio.h>
int addInt(int a, int b); // Adds 2 integers
int add5to4(int (*function_pointer)(int, int));
int main(void)
{
int sum;
int (*function_pointer)(int, int);
}
[code]....
View 2 Replies
View Related
Apr 1, 2013
now that I can pick a mesh I want to put it in the ground.So I'm looking for the 3d position of my mouse in the ground.this is my code about picking:
D3DXMATRIX p_matProjection, p_matView, p_matWorld, p_matInverse;
pDevice->GetTransform(D3DTS_PROJECTION,&p_matProjection);
pDevice->GetTransform(D3DTS_VIEW, &p_matView);
pDevice->GetTransform(D3DTS_WORLD, &p_matWorld);
// use the mouse coordinates to get the mouse angle
[code].....
View 3 Replies
View Related
Aug 17, 2013
Program which accepts two lines and and determines their intersection point and whether they lie within a circle, also given interactively. I'm racing against time and I've racked my skull to no avail
View 2 Replies
View Related
Jul 9, 2014
I dont see any point of NULL in cstring. The code given below just outputs same as it would have done with NULL. My understanding is if size of char array is less than length of char array then null must be manually added?
#include <iostream>
using namespace std;
int main(){
char chr[0];
cin>>chr;//or if you use cin.getline;
cout<<chr<<endl;
return 0;
}
Enter something: hellowwwww
hellowwwww
Segmentation fault (core dumped)
why? for NULL char or something else?
View 1 Replies
View Related
Mar 28, 2014
if we have a decimal number like c=3.46
And i want to set two number, a and b
now a= static_type<int>(c); so a=3;
and i want b= 46
which is the two numbers after the decimal how can I do that ? how can I set b = 46 ?
P.S: i do not know what c equals to. now it's two number after the floating point but it might be more or less
View 7 Replies
View Related