Thursday, April 11, 2013

Program to print alphabet patterns

Love to generate different patterns with C or C++ compilers:
Check this program, this program is able to generate all alphabet patterns from A-Z.
A pattern for line I Love BcaStuff.

Pattern for all characters is generated separately, but I merged them all in a single collage to better view.

Try this code to generate pattern for all 26 alphabets and heart shape :

Program of falling colorful characters

One more colorful program:

Program to draw a hut pattern

Want to draw something new ?
Try this:

Program to print colorful heart pattern

Try this code:

Program to print Heart pattern

Have you tried generating different patterns in C or C++ ?
I know its easy but I am sharing what I tried.

Here is simple Heart pattern.
And will look something like this :

Program to understand concept of Class and Object

After getting the basic difference between syntax of C and C++ we can develop almost all C programs in C++ also. C++ also support same conditional statements, loops and the logic for the code.
Here is the list of C programs that can be developed in C++ also with minor changes in syntax as I described in my last post.
Basic C Programs.

Now we will take a look at new concepts introduced in C++ :

Before reading concept of class you should have basic idea of Structure in C.
Structure allows us to store different data types at one place.
Class also follow the same concept but it is advanced so it enables user to define  function with data members. Means user can define different data members in a class as we do in structure and user can also define functions based on those data members.

Object is a run time entity. Object is a variable of a class, that allows user to access class data members and functions.
It is also known as Instance.

A program to understand class and object concept:

In this program we have class named student which contains s_name, s_address, s_marks[5], s_percentage as data members, and we have two function get() and display(). Here we are using get() function to get value for class data members and display() function to print the value of class data members.
we declared an object like this :

student stud;

Above syntax is to declare an object, student is our class name and stud is our object.
Using this object we are calling class functions get() and display() like this :


So here is all we did with the help of object of the class. We accessed class functions outside the class using objects.

Program to print hello word in cpp

Starting with C++

As we started our first program with Hello word in C now we are doing this with C++.
Environment of C++ has some differences then C environment.
In  C language we use stdio.h for basic input output operation with help of printf() and scanf() functions.
Here we will use cout and cin object defined in iostream.h header file.

Cout is used for output.
Cin is used for input.

For detailed study of basic input/output: Read

A Hello word program here :

Program to use Structure to store student information

Before C++ we had a concept of structure in c language. Structure allows us to hold different types of data in one variable.
For example, if we want to store information of a student, we may have different different information, like name, address, percentage, marks etc. And we know that different fields will use different data types, name and address will need character array, percentage will need float type and marks for multiple subjects will need an integer array.

So to combine all these type of different data types at one place, concept of structure is introduced.

struct student
  char s_name[20];
  char s_address[50];
  int marks[5];
  float percentage;

We use struct  keyword to declare any structure.
And all fields declared inside structure are known as structure members.
now if we want to use these all fields for a single entity then we just need to declare a variable of this type:

struct student stud;

here, a variable stud is able hold all above mentioned information for a student-

To access members of a structure we use  (.) structure reference operator.
For detailed study about structure click here.

Run this program to understand this concept, comment below if you have any query.

Powered by Blogger.