C/C++ :: Rectangle Not Resizing Properly - Odd Multiplication Result
May 28, 2014
I'm having some issues understanding why the "rectangle" in the following code isn't resizing properly. Here's the code:
#include <iostream>
using namespace std;
class Rectangle {
public:
Rectangle(double w, double h, double f)
: width(w), height(h), factor(f)
[Code] .....
I tested the code with a simple multiplication factor of "2", which should result in a new width and height of 4, but instead I get an odd value that seems be close to 4.
Output:
Numerically enter the width of the rectangle: 1
Numerically enter the height of the rectangle: 1
The width of the rectangle is: 1
The height of the rectangle is: 1
The area of the rectangle is: 1
The perimeter of the rectangle is: 4
Numerically enter a number to resize the rectangle: 2
The width of the rectangle after resizing is: 2.07408e-317
The height of the rectangle after resizing is: 2.07408e-317
Point p1(100,100); Point p2(300,200); Graph_lib::Rectangle r(p1,p2);
And also I have a function that takes a rectangle and returns a Point of that, say, top-left corner of that rectangle. For example:
Point N(Graph_lib::Rectangle R1);
My question is that, first, how to send that Rectangle r(p1,p2) to the Point N(Graph_lib::Rectangle R1) function? And then, how to return a Point from that function?
void resize() { int* resize_arr = new int[size + 1];
[Code] ....
i came across this code to dynamically resize an array...and here in the last statement they have deleted resize_arr.As resize_arr and arr points to samething...i think that memory that arr pointing to is also deleted...i guess correct thing would be delete [] arr....before we assign resize_arr pointer to arr...!! i am new to c++...
The plan is to add a new method 'resize' where a new array will copy the contents of the first original array and modify the already existing 'add' method to call 'resize' when necessary.
Up till now, in the constructor I created the new array, should I give the array a default value?
I have a tabbed CDockablePane with 3 Panes in total lets say Pane1 is main pain and Pane2 and Pane3 are added to the Main pain with AttachToTabWnd. In each pain I have 1 control but I will also eventually add a toolbar as well. I have created a CListCtrl with each pane. I call Override OnSize to resize the ListCtrl when the pane resizes. Problem is when I resize the width (enlarge) it does not update. If I drag the right border 1 pixel to the left it does update correctly. I have tried invalidating the pane after resize but still does not update as it should. What can I do to remedy this?
I'm working the 4th problem in chapter 14 of the Jumping into C++ book. In the book, he gives an example program for dynamically resizing an array while the program is running. It works fine for integer types but i need to do the same with a string type array. Right now my program is crashing because the string array is not resizing itself. Here's the part of the code im trying to figure out. The part for the int array has been ignored using // since it works fine and I'm trying to figure out whats wrong with the string array.
Code: #include <iostream> #include <string> //Write a program that lets users keep track of the last time they talked to each of their friends. //Users should be able to add new friends (as many as they want!) and store the number of days ago
I'm attempting to make a matrix class, and so far I've made a member that can make a vector of vectors, but I'm not sure how to go about resizing the vectors if need be.
EX: resizeArray(3,3) should return a 3x3 vector.
Also, for some reason when I call my default member, matrix(), I get an error that says.. "Request for member numrows in myMatrix, which is of type matrix<int>[][]"
#include <iostream> #include <vector> using namespace std;
I think std::copy appears to do what I'm looking for.
I'm in need of a vector member function that would allow me to "insert" a number of elements from one vector into another vector without resizing or destroying either.
An example of what I'm wanting to do is assign the contents of two[3-5][50-54] to one[7-9][2-6]. Other than looping through both vectors using .at(), is there a way to copy this?
This would be continuous within a user controlled loop with differing elements being exchanged.
Apparently the default behavior with Direct2D when rendering is to scale everything I render based on the size of the render target/window. How can I prevent this? I want to decide for myself when to scale the image, regardless of the size of the window.
I made one application in Visual Studio 2008. The main form is maximized, and contains many panels with different controls (like buttons, listboxes, etc,). All the controls have the dock option fixed as true in panels, and the panels occupied the whole area of form.
Now, when I try to run this application in a machine, with different resolution of the screen, the form is maximized (naturally), but the panels are not resizing, so the form has many null area. How can I resize the panel so, that they fill the whole form area?
I have QTextEdit in mainWindow. I'm trying to resize QTextEdit so height = mainwindow.height and width = height/2. That should change when I change the size of mainWindow during runtime. How can I do that?
the code draws rectangle or square it depends on you (column,row) then, put number in the center of the rectangle i don't want to extra space after putting one,two,three or four digits number in the center of the rectangle
I'm trying to make a program that prints a rectangle using "*" asterisks. I am only allowed to use "for loops" and I simply cannot get this to work properly. Here is my code so far...
Code: int main(void) { //RectangleSize represents the area of the rectangle(width*length) int length, width, RectangleSize;
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.
I have having trouble looping through the list in the update section to update each object in the rectangleList. I am not sure how to format it because it is only drawing one and it does not move across the screen. I thought this section of code would work and loop through each object and make each one move but it does not.
for (int i = 0; i < rectangleList.Count; i++) { enemyPosition = new Rectangle(rectangleList[i].X + 2, rectangleList[i].Y ,enemyPosition.Width,enemyPosition.Height); } List<Rectangle> rectangleList; protected override void Initialize() { rectangleList = new List<Rectangle>();
I am making a game Pong, and have been struggling with the collision aspect between the baal hitting off the paddle. I have created a Class, to draw a rectangle, to work with collision however I dont know how to assign the rectangle to the images of the ball and paddle.
I am new to C and am unfortunately racking my brain against this simple assignment. I believe the task is to produce a rectangle out of asterisks using while loops, yet I can only produce an "L" shape. We were given a code, with syntax errors included.We are to correct the errors and test.
Code:
#include <stdio.h> /*Houghton, Micah*/ /*ET2560 - Cordova*/ /*Unit 5 Lab - Programming Loops*/ int main(void) { int length, width; int lcount, wcount;
#include <iostream> #include <cmath> using namespace std;
//prototypes for all separate functions int chooseFunc(int); int chooseMethod(int); int numRect(int);
[Code] .....
It seems that my program will ask the user for the number of rectangles and trapezoids but will fail to compute the area under the curve from the user input. Therefore, I believe I have a logical error somewhere or I'm forgetting to call something somewhere.
[URL] .... This is what I have so far, and it isn't incorrect, but how to improve this or make it more accurate?
// subtracting the area of two circles from a rectangle #include <iostream> using namespace std; int main() { cout << "This program is designed to calculate the area of a rectangle, to exclude the area of 2 circles that have been placed inside of the rectangle." << endl << endl;
Define functions n(), s(), e(), w(), center(), ne(), se(), sw() and nw(). Each takes a Rectangle argument and returns a Point. These functions define connection points on and in the rectangle. For example, nw® is the northwest (top-left corner) of a rectangle called r.
I wrote below code for that:
#include <Simple_window.h> Point n(const Graph_lib::Rectangle& r); Point s(const Graph_lib::Rectangle& r); Point e(const Graph_lib::Rectangle& r); Point w(const Graph_lib::Rectangle& r); Point ne(const Graph_lib::Rectangle& r); Point se(const Graph_lib::Rectangle& r);
[Code]...
As you see, this just mark the top-left corner of the rectangle r. In other functions I need the specifications of that rectangle, for example its height and width. How to use these specs in those functions?
I've been given the task of converting a java application to a c# windows form application. The program displays a Mandelbrot which then allows the user to zoom into. I've managed to display the Mandelbrot and even zoom. However when dragging a box to zoom, the box its self doesn't show, meaning the user cannot see what area they will be zooming into.
I believe I need to call the update function which draws the rectangle as I drag however no matter what I try, I get errors from a red cross instead of the Mandelbrot to compile errors. Here is the code that I believe is relevant.
public void update(Graphics g) { Color color = Color.White; Pen myPen = new Pen(color); g.DrawImage(myBitmap, 0, 0); if (rectangle) {