C++ for electrical engineering... hmm UNISA or well any university likes to lump strange extra subjects on your degree/qualification... maybe they think it will make us smarter..lol , Have you tackled it yet? Sounds lie more electronic engineering... would need C++ as one of a requisite module...sniperx wrote:No This is for electrical engeneering why we need this I dont know bcoz i talked to a few engeneers they dont use any programming and they did visual basic or sumtin like that.
I need help with simple C++ Program!!
The elvin world is different from your world like our ears compared with yours.. to see all the elfs
Art Gallery: www.zananeichan.deviantart.com
You can do it with a single Array of bytes. You just need to make an array big enough to fit in all the data.
int goals;
int cards;
unsigned char data[24*11]; // Use 24 bytes per record;
First 20 bytes correspond to player name
next 2 to store the names
next 2 to store the cards
Seperate function to record the names
for(i=0;i<11;i++)
{
char names[20];
Read names
//store with current formula
strcpy( &data[24*i], named);
}
for(i=0;i<11;i++)
{
// Display name, read goals + cards
memcpy(&char[ (24*record) + 20 ], &goals);
memcpy(&char[ (24*record) + 20 + 2], &cards);
}
The formula for the start segment is 24xrecord (1 - will give you the second record) and +20 offsets to 16 bit int goals, +22 offsets to 16 bit cards) First record is at 0.
You will use this a lot if you go into programming.
int goals;
int cards;
unsigned char data[24*11]; // Use 24 bytes per record;
First 20 bytes correspond to player name
next 2 to store the names
next 2 to store the cards
Seperate function to record the names
for(i=0;i<11;i++)
{
char names[20];
Read names
//store with current formula
strcpy( &data[24*i], named);
}
for(i=0;i<11;i++)
{
// Display name, read goals + cards
memcpy(&char[ (24*record) + 20 ], &goals);
memcpy(&char[ (24*record) + 20 + 2], &cards);
}
The formula for the start segment is 24xrecord (1 - will give you the second record) and +20 offsets to 16 bit int goals, +22 offsets to 16 bit cards) First record is at 0.
You will use this a lot if you go into programming.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Hex_Rated wrote:You can do it with a single Array of bytes. You just need to make an array big enough to fit in all the data.
int goals;
int cards;
unsigned char data[24*11]; // Use 24 bytes per record;
First 20 bytes correspond to player name
next 2 to store the names
next 2 to store the cards
Seperate function to record the names
for(i=0;i<11;i++)
{
char names[20];
Read names
//store with current formula
strcpy( &data[24*i], named);
}
for(i=0;i<11;i++)
{
// Display name, read goals + cards
memcpy(&char[ (24*record) + 20 ], &goals);
memcpy(&char[ (24*record) + 20 + 2], &cards);
}
The formula for the start segment is 24xrecord (1 - will give you the second record) and +20 offsets to 16 bit int goals, +22 offsets to 16 bit cards) First record is at 0.
You will use this a lot if you go into programming.
To be honest I dont have a clue what you are talking about here we havnt learnt that.
Without using structs, it's the only way to do it in a single array. Basically you declare a big chunk of memory and you give each record a known number of bytes (I gave it 24, 20 for the name and 2 x 2 for the 16bit numbers). If you know how big the size of the record is, you can search through them by using an algorithm that knows how many bytes and at what offset the records are at. You can basically write a function that will return whatever you are after. Say you are looking for player 6, it will be at 24x(6-1) = 120. Remember the first record is at position 0 which is why the 6th will be at 5 times the length of your structure.
So 120 bytes down the road and you get your first player name which will be 20 bytes long. If the name is less than 20 bytes long, you must remember to pad the remainder of the string with 0s. You know your goals start at 120+20 bytes and need 2 bytes (optimistic), the number of cards starts at 120+20+2 bytes and also uses 2 bytes.
This is the type of work you can't really study for, it's the most difficult and interesting part of an engineering degree IMO.
Hope this helps, unless I've misinterpreted your question it should be the correct approach to the problem.
So 120 bytes down the road and you get your first player name which will be 20 bytes long. If the name is less than 20 bytes long, you must remember to pad the remainder of the string with 0s. You know your goals start at 120+20 bytes and need 2 bytes (optimistic), the number of cards starts at 120+20+2 bytes and also uses 2 bytes.
This is the type of work you can't really study for, it's the most difficult and interesting part of an engineering degree IMO.
Hope this helps, unless I've misinterpreted your question it should be the correct approach to the problem.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Engineers use programming to solve problems, not just to make software. Mechanical, Civil or Industrial / Chemical engineers would find programming useful to simulate problems. You take a real world problem, take some differential/integral calculus with matrices etc and stick it in the computer and model it. Far easier and more flexible than using a calculator. Basic programming is a required subject for ALL types of engineering, I think even mining engineers get some basic knowledge. Electronics engineers would be taught assembler as well as C++.Zana wrote:C++ for electrical engineering... hmm UNISA or well any university likes to lump strange extra subjects on your degree/qualification... maybe they think it will make us smarter..lol , Have you tackled it yet? Sounds lie more electronic engineering... would need C++ as one of a requisite module...sniperx wrote:No This is for electrical engeneering why we need this I dont know bcoz i talked to a few engeneers they dont use any programming and they did visual basic or sumtin like that.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64