Halloween Costume ideas 2015
Articles by "programmes"



What is Data Structure ?


A data structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths. Data structures can be declared in C++ using the following syntax:

struct type_name {
member_type1 member_name1;
member_type2 member_name2;
member_type3 member_name3;
.
.
} object_names;

Where type_name is a name for the structure type, object_name can be a set of valid identifiers for objects that have the type of this structure. Within braces {}, there is a list with the data members, each one is specified with a type and a valid identifier as its name.

For example:

1
2
3
4
5
6
7
struct product {
  int weight;
  double price;
} ;

product apple;
product banana, melon;


This declares a structure type, called product, and defines it having two members: weight and price, each of a different fundamental type. This declaration creates a new type (product), which is then used to declare three objects (variables) of this type: apple, banana, and melon. Note how once product is declared, it is used just like any other type.

Right at the end of the struct definition, and before the ending semicolon (;), the optional field object_names can be used to directly declare objects of the structure type. For example, the structure objects apple, banana, and melon can be declared at the moment the data structure type is defined: 

1
2
3
4
struct product {
  int weight;
  double price;
} apple, banana, melon;


In this case, where object_names are specified, the type name (product) becomes optional: struct requires either a type_name or at least one name in object_names, but not necessarily both.

It is important to clearly differentiate between what is the structure type name (product), and what is an object of this type (apple, banana, and melon). Many objects (such as apple, banana, and melon) can be declared from a single structure type (product).

Once the three objects of a determined structure type are declared (apple, banana, and melon) its members can be accessed directly. The syntax for that is simply to insert a dot (.) between the object name and the member name. For example, we could operate with any of these elements as if they were standard variables of their respective types: 

1
2
3
4
5
6
apple.weight
apple.price
banana.weight
banana.price
melon.weight
melon.price


Each one of these has the data type corresponding to the member they refer to: apple.weight, banana.weight, and melon.weight are of type int, while apple.price, banana.price, and melon.price are of type double.

Here is a real example with structure types in action:

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
// example about structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

struct movies_t {
  string title;
  int year;
} mine, yours;

void printmovie (movies_t movie);

int main ()
{
  string mystr;

  mine.title = "2001 A Space Odyssey";
  mine.year = 1968;

  cout << "Enter title: ";
  getline (cin,yours.title);
  cout << "Enter year: ";
  getline (cin,mystr);
  stringstream(mystr) >> yours.year;

  cout << "My favorite movie is:\n ";
  printmovie (mine);
  cout << "And yours is:\n ";
  printmovie (yours);
  return 0;
}

void printmovie (movies_t movie)
{
  cout << movie.title;
  cout << " (" << movie.year << ")\n";
}
Enter title: Alien
Enter year: 1979

My favorite movie is:
 2001 A Space Odyssey (1968)
And yours is:
 Alien (1979)
Edit & Run


The example shows how the members of an object act just as regular variables. For example, the member yours.year is a valid variable of type int, and mine.title is a valid variable of type string.

But the objects mine and yours are also variables with a type (of type movies_t). For example, both have been passed to function printmovie just as if they were simple variables. Therefore, one of the features of data structures is the ability to refer to both their members individually or to the entire structure as a whole. In both cases using the same identifier: the name of the structure.

Because structures are types, they can also be used as the type of arrays to construct tables or databases of them:

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
// array of structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

struct movies_t {
  string title;
  int year;
} films [3];

void printmovie (movies_t movie);

int main ()
{
  string mystr;
  int n;

  for (n=0; n<3; n++)
  {
    cout << "Enter title: ";
    getline (cin,films[n].title);
    cout << "Enter year: ";
    getline (cin,mystr);
    stringstream(mystr) >> films[n].year;
  }

  cout << "\nYou have entered these movies:\n";
  for (n=0; n<3; n++)
    printmovie (films[n]);
  return 0;
}

void printmovie (movies_t movie)
{
  cout << movie.title;
  cout << " (" << movie.year << ")\n";
}
Enter title: Blade Runner
Enter year: 1982
Enter title: The Matrix
Enter year: 1999
Enter title: Taxi Driver
Enter year: 1976

You have entered these movies:
Blade Runner (1982)
The Matrix (1999)
Taxi Driver (1976)
Edit & Run


Pointers to structures
Like any other type, structures can be pointed to by its own type of pointers:

1
2
3
4
5
6
7
struct movies_t {
  string title;
  int year;
};

movies_t amovie;
movies_t * pmovie;


Here amovie is an object of structure type movies_t, and pmovie is a pointer to point to objects of structure type movies_t. Therefore, the following code would also be valid:


pmovie = &amovie;


The value of the pointer pmovie would be assigned the address of object amovie.

Now, let's see another example that mixes pointers and structures, and will serve to introduce a new operator: the arrow operator (->):

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
// pointers to structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

struct movies_t {
  string title;
  int year;
};

int main ()
{
  string mystr;

  movies_t amovie;
  movies_t * pmovie;
  pmovie = &amovie;

  cout << "Enter title: ";
  getline (cin, pmovie->title);
  cout << "Enter year: ";
  getline (cin, mystr);
  (stringstream) mystr >> pmovie->year;

  cout << "\nYou have entered:\n";
  cout << pmovie->title;
  cout << " (" << pmovie->year << ")\n";

  return 0;
}
Enter title: Invasion of the body snatchers
Enter year: 1978

You have entered:
Invasion of the body snatchers (1978)
Edit & Run


The arrow operator (->) is a dereference operator that is used exclusively with pointers to objects that have members. This operator serves to access the member of an object directly from its address. For example, in the example above:


pmovie->title


is, for all purposes, equivalent to: 


(*pmovie).title


Both expressions, pmovie->title and (*pmovie).title are valid, and both access the member title of the data structure pointed by a pointer called pmovie. It is definitely something different than:


*pmovie.title


which is rather equivalent to:


*(pmovie.title)


This would access the value pointed by a hypothetical pointer member called title of the structure object pmovie (which is not the case, since title is not a pointer type). The following panel summarizes possible combinations of the operators for pointers and for structure members:

Expression What is evaluated Equivalent
a.b Member b of object a
a->b Member b of object pointed to by a (*a).b
*a.b Value pointed to by member b of object a *(a.b)

Nesting structures
Structures can also be nested in such a way that an element of a structure is itself another structure:

1
2
3
4
5
6
7
8
9
10
11
12
struct movies_t {
  string title;
  int year;
};

struct friends_t {
  string name;
  string email;
  movies_t favorite_movie;
} charlie, maria;

friends_t * pfriends = &charlie;


After the previous declarations, all of the following expressions would be valid:

1
2
3
4
charlie.name
maria.favorite_movie.title
charlie.favorite_movie.year
pfriends->favorite_movie.year


(where, by the way, the last two expressions refer to the same member).
Download Data Structure Programmes




Definition - What does C++ Programming Language mean?


C++ is a general-purpose object-oriented programming (OOP) language, developed by Bjarne Stroustrup, and is an extension of the C language. It is therefore possible to code C++ in a "C style" or "object-oriented style." In certain scenarios, it can be coded in either way and is thus an effective example of a hybrid language.

C++ is considered to be an intermediate-level language, as it encapsulates both high- and low-level language features. Initially, the language was called "C with classes" as it had all the properties of the C language with an additional concept of "classes." However, it was renamed C++ in 1983.

It is pronounced "see-plus-plus."

C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.

This reference will take you through simple and practical approach while learning C++ Programming language.

Audience
This reference has been prepared for the beginners to help them understand the basic to advanced concepts related to C++ Programming languages.

Prerequisites
Before you start doing practice with various types of examples given in this reference, I'm making an assumption that you are already aware about what is a computer program and what is a computer programming language?

Execute C++ Online
For most of the examples given in this tutorial you will find Try it option, so just make use of this option to execute your C++ programs at the spot and enjoy your learning.

Try following example using Try it option available at the top right corner of the below sample code box −

#include <iostream>
using namespace std;

int main() {
   cout << "Hello World";
   return 0;
}

Download C++ Programmes


What is C+?


The C+ is known as the base for the development of the object oriented programming.C++ i.e is known as object oriented language is generated from the C+.
C# is a C like language made by MS to try and suit their own needs and make writing applications for Windows and other MS products more easy.


Feel free to ask for more specific details, I use all three of these at work on different things.


C was written in the 70's for OS development and became very popular, and still is. C+ doesn't exist. C++ is a play on the ++ operator that exists in C, and is meant to provide additional, higher level features to the C language. (It's floated a bit from this; it's no longer perfectly backwards compatible as it was in the start. Still very similar though.) Mostly it's used when you want to use C, but also want to write object-oriented code and/or use templates which can be amazingly useful.

C+ isn't a programming language.

C came first, then C++. These two languages have built an enormous portion of modern software and they've been around for a while. Programmers using them have an enormous amount of control over the computer. Though as they say "with great power comes great responsibility", it's extremely easy to cause yourself big problems using C or C++ if you're making a larger program and you're not that experienced with them.

C++ was early on described as "C with classes". Classes being a reference to "object oriented program" (search ELI5 for great explanations of that). It's more likely than not if you are using a computer program you're using something built on top of C or C++. The "++" in programming often mans increment, or "make this thing one larger than it is". C++ therefore means "C but a little better"
C# is a more modern language. It is easier to make modern looking useful programs quickly than C or C++ and some technical details are handled at a lower level for you. It does look similar to C++ but it is built completely around the idea of "object oriented programming", instead of it being an added on feature like with C++.

They are all different programming languages. C+ doesn't exist.

C++ and C# are named after C because they have similar syntax to C. C is a subset of C++.
For all intents, the 3 languages are all different from each other.

Download C+ Programmes

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget