-- Learning C++ -- - Page 3
You are Unregistered, please register to gain Full access.    
Desi Forums   


Go Back   Desi Forums > Ray Of Light > Tech Talk > Tutorials Cafe

Notices

-- Learning C++ --

  Discuss -- Learning C++ -- at the Tutorials Cafe; Exms Up.All tuts halted till 14th July. Bear me....

Reply
 

 
Thread Tools
  #31 (permalink)  
Old 05-14-2008, 02:19 PM
mytonse's Avatar
Exorbitant
Location: India
Gender:
Visit mytonse's Blog
 
Join Date: Dec 2005
Age: 19
Posts: 3,368
Credits: 35,704
mytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of light
Send a message via MSN to mytonse Send a message via Yahoo to mytonse Send a message via Skype™ to mytonse
Exms Up.All tuts halted till 14th July.

Bear me.
Reply With Quote
Sponsored Links
  #32 (permalink)  
Old 08-09-2008, 03:30 AM
@sd's Avatar
@sd @sd is offline
Debonair
Location: United Arab Emirates
Gender:
 
Join Date: Jun 2008
Posts: 89
Credits: 295
@sd is on a distinguished road
loveelllii thread
Reply With Quote
  #33 (permalink)  
Old 08-11-2008, 02:03 AM
mytonse's Avatar
Exorbitant
Location: India
Gender:
Visit mytonse's Blog
 
Join Date: Dec 2005
Age: 19
Posts: 3,368
Credits: 35,704
mytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of light
Send a message via MSN to mytonse Send a message via Yahoo to mytonse Send a message via Skype™ to mytonse
Thank You there..will continue soon
Reply With Quote
  #34 (permalink)  
Old 08-12-2008, 04:20 AM
mytonse's Avatar
Exorbitant
Location: India
Gender:
Visit mytonse's Blog
 
Join Date: Dec 2005
Age: 19
Posts: 3,368
Credits: 35,704
mytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of light
Send a message via MSN to mytonse Send a message via Yahoo to mytonse Send a message via Skype™ to mytonse
Post Class 5-ARRAYS

Arrays are useful critters because they can be used in many ways. For example, a X&0 board can be held in an array. Arrays are essentially a way to store many values under the same name. You can make an array out of any data-type including structures and classes.

Arrays are represented in square brackets.for eg [][][][][][] where
each of the bracket pairs is a slot(element) in the array, and you can put information into each one of them. It is almost like having a group of variables side by side.

Lets look at the syntax for declaring an array.

for example int a[100]; // This declares an array

This would make an integer array with 100 slots, or places to store values(also called elements). To access a specific part element of the array, you merely put the array name and, in brackets, an index number. This corresponds to a specific element of the array. The one trick is that the first index number, and thus the first element, is zero, and the last is the number of elements minus one. 0-99 in a 100 element array, for example.

What can you do with this simple knowledge? Lets say you want to store a string, because C had no built-in datatype for strings, it was common to use arrays of characters to simulate strings. (C++ now has a string type as part of the standard library.)

For example:

char a[100];

will allow you to declare a char array of 100 elements, or slots. Then you can receive input into it it from the user, and if the user types in a long string, it will go in the array. The neat thing is that it is very easy to work with strings in this way, and there is even a header file called cstring. There is another lesson on the uses of strings, so its not necessary to discuss here.

The most useful aspect of arrays is multidimensional arrays. How I think about multi-dimensional arrays:

[][][][][]
[][][][][]
[][][][][]
[][][][][]
[][][][][]


This is a graphic of what a two-dimensional array looks like when I visualize it.

For example:

int a[8][8];

declares an array that has two dimensions. Think of it as a chessboard. You can easily use this to store information about some kind of game or to write something like tic-tac-toe. To access it, all you need are two variables, one that goes in the first slot and one that goes in the second slot. You can even make a three dimensional array, though you probably won't need to. In fact, you could make a four-hundred dimensional array. It would be confusing to visualize, however. Arrays are treated like any other variable in most ways. You can modify one value in it by putting:

arrayname[array number] = desired designation;

or, for two dimensional arrays

arrayname[array number1][array number2] = desired designation;

However, you should never attempt to write data past the last element of the array, such as when you have a 10 element array, and you try to write to the [10] element. The memory for the array that was allocated for it will only be ten locations in memory, but the next location could be anything, which could crash your computer.

You will find lots of useful things to do with arrays, from storing information about certain things under one name, to making games like the x&0 board. One suggestion I have is to use for loops when access arrays.

#include <iostream>

using namespace std;

int main()
{
int x;
int y;
int a[8][8]; // Declares an array like a chessboard

for ( x = 0; x < 8; x++ ) {
for ( y = 0; y < 8; y++ )
a[x][y] = x * y; // Set each element to a value
}
cout<<"Array Indices:\n";
for ( x = 0; x < 8;x++ ) {
for ( y = 0; y < 8; y++ )
cout<<"["<<x<<"]["<<y<<"]="<< a[x][y] <<" ";
cout<<"\n";
}
cin.get();
}

Here you see that the loops work well because they increment the variable for you, and you only need to increment by one. Its the easiest loop to read, and you access the entire array.

One thing that arrays don't require that other variables do, is a reference operator when you want to have a pointer to the string. For example:

char *ptr;
char str[40];
ptr = str;
// Gives the memory address without a reference operator(&)

As opposed to

int *ptr;
int num;
ptr = &num;
// Requires & to give the memory address to the ptr

The reason for this is that when an array name is used as an expression, it refers to a pointer to the first element, not the entire array.

my my,...we are done with studies today.

Any doubt /suggestionsbwill be greatly appreciated,Our Helpdesk personnels at Desitwist will be glad to assist you.

Thank you.
Reply With Quote
  #35 (permalink)  
Old 08-28-2008, 04:45 PM
mytonse's Avatar
Exorbitant
Location: India
Gender:
Visit mytonse's Blog
 
Join Date: Dec 2005
Age: 19
Posts: 3,368
Credits: 35,704
mytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of lightmytonse is a glorious beacon of light
Send a message via MSN to mytonse Send a message via Yahoo to mytonse Send a message via Skype™ to mytonse
This is to inform the readers that unless until ,anyone who reads this gives me a green signal ...am not continuing not only this but any of my other tuts at desi...

Really katti with you guys..better do it quick before i think to stand down...
Reply With Quote
  #36 (permalink)  
Old 08-29-2008, 10:49 AM
RAHEN's Avatar
Team leader
Location: United Arab Emirates
Gender:
Visit RAHEN's Blog
 
Join Date: Apr 2006
Age: 24
Posts: 36,378
Credits: 363,835
RAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to beholdRAHEN is a splendid one to behold
Yunus, will want leave from this tutorial at the moment...as there are many other schedules to follow..inshaALLAH when i will finish with those..i will want to learn from ur material...
thanks for all ur time consuming tutorials...would appreciate if u carry on completing it.
Reply With Quote
  #37 (permalink)  
Old 09-07-2008, 09:34 AM
spotlesssoul's Avatar
Exorbitant
Location: Pakistan
Gender:
Visit spotlesssoul's Blog
 
Join Date: Jul 2006
Age: 17
Posts: 1,519
Credits: 18,810
spotlesssoul is a glorious beacon of lightspotlesssoul is a glorious beacon of lightspotlesssoul is a glorious beacon of lightspotlesssoul is a glorious beacon of lightspotlesssoul is a glorious beacon of light
Can we have tutorial for C programming firstly?!*innocent smiley*
Reply With Quote
Reply

Bookmarks

Tags
c language, computer language, functions, information technology, learn, programming, tutorial, variables


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Learning, knowledge vis-a-vis Attitude sikandar107 Student Zone 6 08-09-2008 03:41 AM
Why choose distance learning? *Saira* Student Zone 0 03-22-2007 10:20 PM
If learning is unuseful? Jugnoh Teen Talks 14 02-28-2007 01:42 PM
Learning to Fly (For Adeeloo) xeon Bollywood Unlimited 4 09-23-2005 08:55 PM




Mobile Phone Loans Debt Help Gas Suppliers Credit Card Consolidation




1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44