C++ :: Chronological Arrangement Of Two Time Objects
Jul 8, 2013
I have a class that I can simply define as (I have simplified the class):
Code:
class Time{
public:
Time(int hour,int minute,int second):hour(hour),minute(minute),second(second){}
private:
int hour;
int minute;
int second;
};
Is it possible to check for chronological arrangement of two time objects most possibly without using an if statement ? Well this is off topic but there may be a python guru around,..is it possible to do similar thing in python?
View 5 Replies
ADVERTISEMENT
May 25, 2014
I am doing a remake of the classic game: Frogger. Currently, I have the world set up, the frog moves about in the world how I want it to, but I cannot get the cars or the logs to move simultaneously with the frog. I have posted my source code on GitHub.
[URL]
View 16 Replies
View Related
Sep 20, 2014
The question is to write a program to add two time objects.
Here's what I did:
#include<iostream.h>
#include<conio.h>
class Time {
public:
int hours,minutes,seconds;
[Code] .....
There's an error in sum of hours in the output.
View 5 Replies
View Related
Mar 10, 2015
This is a round robin execution. with gantt chart. arrival time and burst time. I think there is an error in my formula to get the right answer,i cant resolve it but my program is running. What is the code or the right formula??
#include<stdio.h>
int main(){
int i,j=0,n,time,remain,flag=0,ts;
int sum_wait=0,sum_turnaround=0,at[10],bt[10],rt[10];
int ganttP[50],ganttStartTime[50];
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;
[Code] ....
View 2 Replies
View Related
Nov 12, 2014
This has been bothering me for a while now, and I finally put together an example:
#include <iostream>
#include <string>
using namespace::std;
[Code]....
In the code above, the two classes hold pointers to each other, and that's fine but it doesn't seem right since C++ prefers to pass by reference. Yes, it can still do that (see testbox and testball) but even that seems odd to me because still you need to use pointer notation for the enclosed object. Am I the only one who feels this way, and should I just get over it? Or am I missing something that would allow an object to hold a reference?
View 4 Replies
View Related
May 1, 2013
So I'm trying to learn how to use time for time based movement and what not. I did this only knowing the command time(&variable)
time_t timer;
int I, X;
void main() {
time(&timer);
X=timer;
while(I==5) {
[Code] ......
There's probably some other better way to do it... Obviously but for now I see it as putting current time in X.
start while
take in time constantly until I is 5
constantly asking is time>X(preset time 5 seconds ahead)
if it is
display message and add one to I
Why doesn't this display my message after 5 seconds?
View 1 Replies
View Related
Mar 18, 2013
make a time-in time-out fuction which extracts the no. of hours and minutes from a string entered by the user.
#include <iostream>
#include <fstream>
#include <string>
[Code].....
View 3 Replies
View Related
Mar 6, 2014
when we would use add items at design time and when we would add them at run time
does it have anything to do with the page load method? if so, can i type this in source code instead?
View 2 Replies
View Related
Apr 2, 2013
i am relatively new to c++, and am trying to make it so particles will gravitationally attract to the mouse pointer. i have gotten all the bugs that the compiler found, but there must be another because the program crashes the second i open it. my code could be way off, so just tell me if it is and ill do more research and learning before trying something like this again. here is the code:
#include <SDL/SDL.h>
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
using namespace std;
float mouseX;
float mouseY;
[Code] .....
View 6 Replies
View Related
Oct 20, 2014
I've been really busy but managed to get in enough down time to learn somewhat decent info about vectors. Anyways originally my program created a dynamic array of pointers to class objects and I came across a few problems because of this. Apparently an array of pointers is now outta of the question and I will now be switching to a vector of objects instead.
Why I want a list of objects instead of pointers this little comment should clear things up.
tiles[i]->show() dereferences tiles[i] (i.e. accesses whatever it points at) before calling the show() method.
That is undefined behaviour. Once undefined behaviour occurs, there is no recovery, and there is nothing the show() method (or any subsequently called function for that matter) can do to recover (short of invoking their own forms of undefined behaviour - compiler specific hacks, etc).
Even if the show() method initialises the object correctly, it cannot change the pointer tiles[i] which is in a different scope (within main()).
What I'm trying to do is create a vector of already intialized objects so that I can use a conditional statement of every single element to properly layer my games art resources. This should also automatically fix a mild unrelated collision dectection problem too but first thing first layering.
View 9 Replies
View Related
Nov 10, 2013
here's the problem. I want to delete the objects within a vector, although I'm not sure whether I should clear the vector afterwards. Is it really necessary?
Code:
for (i = 0; i < allSales.size(); i++)
delete allSales[i];
allSales.clear(); //Is this step necessary?
View 5 Replies
View Related
Aug 25, 2013
well the question is how to compile objects in a subdirectory?
Code:
./bo/%.o : %.c
$(CC) $(CFLAGS) <$
the command abouve will compile my objects but leave them in the same directory. However I want them in a different directory. in ./bo directory. How to achieve that ? I just realize that if i remove ./bo/ from the line it does not work..
View 3 Replies
View Related
Jun 6, 2013
I am using OpenCV to read and manipulate a set of images, which I need to store in an array to work with them. Here is a snippet of the code:
#define MAX_IMAGES 8
typedef Mat* MatPtr;
int main(int argc, char** argv) {
char imageName[] = "./res/imageX.tiff";
MatPtr datacube[MAX_IMAGES];
[code].....
I have an array of pointers to Mat objects (an OpenCV class used to hold info and data about an image), which I will use to store the images. The function imread reads an image and returns a Mat object loaded with the relevant data about the image.However, this gives me a nice segfault when the assignment takes place. Of course, I can swap it with the following code, but since I'm working with big images (2048x2048 and upwards), it's really inefficient:
for(unsigned int i = 0; i < MAX_IMAGES; i++) {
imageName[11] = 49 + i;
datacube[i] = new Mat(imread(imageName, -1));
}
Is there any way to do this elegantly and without much hassle?Again, excuse my rustiness and anything completely stupid I might have said. It's been a long time since I worked with C++. Managed to circumvent the problem by using a STD vector instead of an array. I'd still like to know the answer to this riddle...
View 6 Replies
View Related
Oct 12, 2014
class FlashCard {
public:
int a,b;
void PrintCard(void);
int CorrectAnswer(void);
};
void SwapFlashCard(FlashCard &a,FlashCard &b)
[Code]....
Why does Xode warn me that Type'FlashCard'does not provide a subscript operator on line 22,23,29 and 30?
View 7 Replies
View Related
Jun 25, 2013
I have the following code below. I am getting a memory access violation when accessing cmd->query_string in the loop function. The loop() function is running in another thread. The cmd object appears to be destroyed after calling the send_command function. How do I create an object on the heap and access the query_string.
std::list<my_command_message_que*> my_command_que;
void loop(){
if(my_command_que.size() > 0){
my_command_message_que * cmd = my_command_que.front();
std::cout << cmd->query_string;
[Code] ....
View 2 Replies
View Related
Jul 24, 2013
I keep getting an undesired value in this code. I've tried several methods, but none are giving me the correct answer. The out put is always zero, when in this case it should be 10!!
Here's the object structure:
template<class T, class _b>
struct quantity {
private: T value;
public:
explicit quantity(T val): value(val) {};
T getValue() { return value; };
[Code] .....
Here's the operation:
int main() {
quantity<int, bool> m(20);
quantity<float, bool> m_f(10);
quantity<double, bool> m_d(NULL);
m_d = m_f;
[Code] .....
Why does it seem that the assignment operator is the harder operator to overload? Maybe it's just my luck, but I seem to always run into issues whenever I work with it. I hardly ever experience errors when overloading any of the other operators.
View 6 Replies
View Related
May 20, 2013
I have a question regarding how GCC relates a header file and its binary file.
main.c
#include <math.h>
#include <stdio.h>
int main (void){
double x = sqrt (2.0);
printf ("The square root of 2.0 is %f
", x);
return 0;
}
we can compile it by running the line: gcc main.c -lm -o main
My question is: How GCC knows where is the definition of sqrt?
First I was thinking that there was and object file with the name math.o inside libm.a (that is GCC will look for an object file with the same name as the header file), but after running the next line I think my assumption was wrong as there is not such file in libm.a.
nm libm.a | grep math.o
nm: e_acos.o: no symbols
nm: k_cos.o: no symbols
nm: k_sin.o: no symbols
[Code] ....
View 7 Replies
View Related
Nov 14, 2013
I've started programming my little program called vLibrary (program I want to make for the library in my city) and after I m done with console application I will try to implement wxWidgets.My program will be able to add new users to the system, new books and new librarians.
Now, I m confused what data types to use and how to store objects (newly created users, books etc) to my program so later on they can log in the system etc. Logic of the program is completely clear to me but I m not sure how to make array of objects and store them in memory or in a certain file, how to store password and make some kind of encryption etc.which data structure from STL should I use and how.
View 2 Replies
View Related
Feb 8, 2014
I'm currently trying to access a variable contained within a base object from another completely different object and I continually get error messages. I'll attempt to put up the important code since it's contained within fairly large classes. From the Base .cpp file. ObjectPosition:
void ObjectPosition::init(float x,float y, float speed, int boundx, int boundy, float hit, int lives, bool live) {
ObjectPosition::x = x;
ObjectPosition::y = y;
ObjectPosition::speed = speed;
ObjectPosition::boundx = boundx;
ObjectPosition::boundy = boundy;
ObjectPosition::hit = hit;
ObjectPosition::lives = lives;
ObjectPosition::live = live;
}
This is the initialization function for the BaseObject. All objects are inheriting these variables which are Protected within the ObjectPosition class.Then they are initialized within the Pig class thus wise:
void Pig::binit(float sx,float sy, ALLEGRO_BITMAP *simage) {
//Sets all ObjectPosition Variables
ObjectPosition::init(800,900,10,80,40,40,10,true);
smaxFrame = 4;
scurFrame = 0;
[code]...
I tried to initialize the boundx through the pig via pinitx but I get errors and I can't access through the pig to the object position to the boundx.
View 10 Replies
View Related
Dec 30, 2014
How to get this code working
template <typename T>
class Dummy {
// Implementation
};
template <typename T>
class SomeClass
[Code] ......
View 4 Replies
View Related
Oct 31, 2014
I have two classes, Parent and Child, where Parent contains a vector that is used to store instances of Child. When I create an instance of Parent, three instances of Child are also created in Parent's constructor and stored in the vector. I understand that push_back() creates a shallow copy of each Child instance and that Child's destructor is called each time the loop (inside Parent's constructor) iterates. The problem is that because Child's destructor is called each time the local variable child goes out of scope, the memory previously allocated in Child's constructor is destroyed and when Child's destructor is called again later on in the program to get rid of the copy stored in vector, the program crashes. I can fix this by overriding the default copy function or by storing pointers to objects instead of copies of objects. I don't really need to use vectors in this case since I always have three children in one parent but I'm doing this as a learning exercise and would prefer to use vectors.
#include <iostream>
#include <vector>
class Child {
public:
Child() {
std::cout << "child constructor called" << std::endl;
[Code] .....
View 3 Replies
View Related
Nov 6, 2013
I my code i have a base struct ...
Then others structs made ...
struct base{};
struct a1 : base {
int a;
int b;
[Code] ....
Now i must deposit all these containers(maybe & of containers) in another vector...
How i can do that? Can i write
vector<vector<base*> > all;
all.push_back(&v1);
all.push_back(&v2);
View 14 Replies
View Related
Sep 27, 2013
I've created an Array of pointers to objects using:
Person ** A = new person * [arraysize];
When I intend to access a specific person do I have to do this? :
something = A->[i];
and when I want a specific object within my struct do I have to do this? :
something_else = A->[i]->random_int;
View 10 Replies
View Related
Oct 27, 2014
I'm using the SDL library and trying to match the C++11 standards... Anyway, I thought about a vector where I store all the addresses of game instances, so I can access them anytime... I tried with this function:
int instance_new(std::vector<uintptr_t> &instance_id, unsigned &instance_size, Instance *pointer) {
instance_id[instance_size] = reinterpret_cast<std::uintptr_t>(pointer);
instance_size++;
instance_id.resize(instance_size);
return 0;
}
Where "Instance" is the 'parent' class of various child classes like the player. So, if I have to search the existing of a thing in my game, I should check if the address references to an instance of class. How can I do this?
View 1 Replies
View Related
Mar 1, 2014
I am preparing for an exam, and I am being told there will be, "1 multiple-choice question about reading a piece of code about objects interacting with functions and deciding the output."
There are a few ways I can think of:
- Passing an object into a function as an argument
- An object calling a function with a dot operator
- Creating a new object through a Constructor and Class(Does that count?)
Are there other ways that objects interact with functions that I am not thinking of?
View 1 Replies
View Related
Apr 25, 2014
How do we design a container of objects all of which belong to some subclass which directly/indirectly inherits from a given parent class? Moreover, I would like to have functions that enable me to pick only objects of a certain class type from the container.
For example if the parent class is A and I have a hierarchy of classes that derive from it, we must have a container that can contain any class that exists in this hierarchy. Also, get_B() must be able to let me examine only those objects in this container that inherit (directly/indirectly) from class B (class B exists in the hierarchy rooted at A).
Preferably, we would like to avoid downcasting. Or even explicit typechecking of any sort.
View 8 Replies
View Related