I have a quick question. I need a way to represent orientation in degrees. I made a class which automatically changes negative angles into positive ones (adds 360 until >0) and makes sure they are under 360 (subtracts 360 until <360).
Now I realized I also need a class to represent angular movement, which must be in the range ]-360;360[
I don't think custom types with the unsigned keyword is a thing, but I'm just looking for a better way to do this then making two classes. Or would you just create a class which inherits from angle and overloads a few methods?
Or I could just use floats to represent rotation, because testing if an object does more than 1 turn per second isn't really required.
I am drawing in a simple (square) MFC window. I realize that (0,0) starts in the upper left hand corner. I wanted to see how MFC handled drawing of angles, so I use this code:
Code: double CompassDegreesToRadians(double compassDegrees) { return((PI / 2.0f) - (compassDegrees * PI / 180.0f)); } // Make pen CPen penRed; penRed.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(255, 0, 0)); // Test Angles
[Code] .....
Using this code, and changing the value of angle1 to these values (0, 90, 180, 270) I think MFC uses the coordinate system:
This seems like a strange coordinate system to use. Am I doing something wrong? If this is correct, how can I convert my calculations to this coordinate system? (compass degrees):
Given an array of angles A = [0 30 60 90 120 150 180 210 240 270 300 330 360]
Write a program that will generate the data set of angles automatically and provide three columns; sin(angle), cos(angle), tan(angle). Make this program as compact and readable as possible.
I am currently stuck on what I should do next in a program I am working on. These are my instructions:
Design, implement, and test a class for storing integer arrays "safely". The array should be able to hold any number of integers up to 100.
In the class header file "SafeArray.h" students must define the class and specify the constructor/destructor functions, the public methods and private variables. In the class implementation file "SafeArray.cpp" students must implement the following operations:
constructor - to initialize the object. copy constructor - to copy an object. destructor - to delete the object. set - allow the user to set a value of the array at a particular location. get - allow the user to get a value of the array at a particular location. print - print out the array. add - add the elements of one array to another. subtract - subtract the elements of one array from another.
The output of my program is suppose to look like this:
Set q1: 2, 3, 4 Print q1: 2, 3, 4
Set q2: 1, 4, -2 Print q2: 1, 4, -2
Add q2 to q1
Print q1: 3, 7, 2 Get q1 at 1: 7
Here is the code I have so far.
*main.cpp*
#include <iostream> #include "SafeArray.h" using namespace std; int main() {
I've a text file : Random.txt which comprises of Jade 12MS234 Male 18 Rocky 12MS324 Male 18 Marx 12MS632 Male 18
Now in my program i've a class class stud { char name[10]; char reg[10]; char gender[10]; int age; };
Now I've to write a code in c++, where i've to read the given data and store this into 3 objects of stud class(array of objects) ...then further i've to manipulate the above stored data. I think i'm getting error while storing...variables are showing random characters... give me the code.for this program..in C++
Im trying to make a c++ program for a school project, and i need to store the information into binary files, but I'm having some problems trying to store a class with string members, for example:
class whatever{ protected: string name; public: (List of functions) }
But if I do that, my code just dont work when I write and read a binary file, but if I change the string to char array, for example:
class whatever{ protected: char name[20]; public: (List of functions) }
It works good, so I wanted to know if there's some way to store a class wiht strings in binary files, or what am I doing wrong?
#include <list> #ifdef TICKABLE_EXPORTS //Automatically defined by MSVS #define DLL __declspec(dllexport) #else #define DLL __declspec(dllimport) #pragma comment(lib, "Tickable.lib") #endif
class DLL Tickable{
[Code] ....
error LNK2001: unresolved external symbol "private: static class std::list<class Tickable*,SKIPPED BITS> Tickable::subs" HUGE_SYMBOL_LIST PATHTickable.obj
I know with such a tiny and insignificant class the dll export seems pointless but this class is actually intended to be a .lib ONLY. But it is derived from by .dll style classes, and through inheritance this error is the exact same as what appears in the derived class, I just imagine that the cut down version would be easier to work with.
Is it possible to hold either a static variable in a dll which is of a dynamic type, OR would it be possible to reference an external variable which is static throughout the instances and this variable can be chucked away in a namespace of mine somewhere?
I suppose my only other option (if this is possible) would be to define a maximum instance number and create a standard array of pointers but this could both waste so much memory when not in use and cause problems if I need more memory.
{ int codice; char* nome; char* cognome; int esami; printf("Leggi uno studente da tastiera e memorizzalo in una struct "); lettura_studente(s1, codice, nome, cognome, esami); return 0; }
[code]....
In conclusion I'va two problems:
1) Program crash; 2) I can't read struct studente within parameter function. What are the problems?
I see many time where static data member is used to count creations of objects -
i.e.
1. the static data member is init to 0
2. the static data member is incremented by 1, in the Class' constructor, every time an object is created
However, if you define a global object of a class,
How can you tell that the static data member is initialized BEFORE the constructor of the global object is called? (i.e. before the global object is created).
Because to my understanding, you do not know in advance the order of global objects' creation -
so the Global Object could be created BEFORE the static data member was created and initialized.
I'm trying to write a function that takes a 32bit address and a data to store at this address.
I'm wanting to take the 32 bit memory address eg 0x12345678 and split it into 4 x 2 bytes 12, 34, 56, 78
then each of the 4 entries is at most a 256 entry array.eg FF, FF, FF, FF
So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.
After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.
The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.
It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.
void cpu::store(unsigned int mem_add,unsigned int mem_val) { int first = (mem_address&4278190080)>>24; int second = (mem_address&16711680)>>16; int third = (mem_address&65280)>>8; int fourth= (mem_address&255);
I have a project to do in C and coming form Java I miss all the included features that are missing from C! I need to be able to store key value pairs in an quick and memory efficient manner. I've looked up using hash maps but I'm very new to C so don't really understand even the basic ones. I've looked at using a multi-dimensional array as I'm more comfortable with arrays but I'm unsure if that would count as a memory efficient and quick method?
So i'm creating bank system. Where I have function that reads the text file (balance), and I make a deposit, which adds what was in the balance = deposit + balance.
But this is what is happening. In my text file i have number 10. Function balance works fine and reads 10 from the text file.
When I make a deposit add a value to the balance, if i add 7, the new balance is 17. And i check the text file shows me is 17. Which is correct.
The problem is here. If i make another deposit, without closing the program, for example i add 5 to the balance, the new balance should be 22 = 17(balance) + 5(deposit), because 17 was store on the text file and it was the balance that was store on the text file on the last time. But it shows me 15, it adds the balance that the program first started which was 10(balance) + 5(deposit), but should had had be 17 + 5.
When I close the program the value on the text file, is 15, that was the last sum that i did.
I then realized that the order that the second method gave me will make it very hard for me to calculate the RGBs. Because they will be calculated like wise..
P3 600 339 255 44 5 8 = sum 44 5 8 = sum 43 4 7 = sum 42 3 6 = sum
I wanted to find all the prime until a specified limit in C. I use the Sieve of Eratosthenes. But when I define the limit to anything more than a 7 digit number the program terminates.
Code:
#include<stdio.h> #define limit 1000000000 int main(void) { unsigned long long int i,j; int primes[limit] = {0}; //int count =0; for(i=2;i<limit;i++) }
[code]....
I believe that this might be because the size cannot be declared array cannot be more than the a 7 digit number. I think so. how to store a 10 digit number in C?And can't unsigned long long hold a 10 digit?
I have a file that can range from 100 rows to 10000+ that is comma delimited with 8 columns. The first 32 rows (also comma delimited) will always be ignored (geographical header information). I will be wanting the data from column2 and column3.
For this I believe I would need (2) For Loops as such:
I have a base class Building. Then come its children classes - Commercial Building and Residential Building. The third level is composed of Apartment and House classes, both inherit from Residential Building.
I need to create an array of 20 elements that will store info about all these different types of buildings(Commercial Building,Residential Building,Apartment, House). How should I proceed?
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.