Showing posts with label C Programming. Show all posts
Showing posts with label C Programming. Show all posts

What Is Object Oriented Programming Lanugages

Posted by Tushar Bedekar
There are basically two eras of the programming languages to which we have seen which are as follow:-

  • Structured (procedure) oriented programming language
  • Object oriented programming language
There are many structure oriented programming languages such as C, Cobol, Pascal, Assembly languages etc. where we make use of functions (procedures) and supposed to write the programme sequentially with the data and functions mashed up in the form of the sequential statements.
Here in the procedures oriented language the data is allowed to flow freely in the programme.A confusing statement. To understand it let's take an example we have a programme which consist of global variable declaration and being assessed by the two or more number of functions as given bellow

#include<stdio.h>
int a=10;

int add()
{
int b=5;
a=a+b;
printf("%d",a);
}

int sum()
{
int c=7;
a=a+b;
printf("%d",a);
}

int main()
{
add();
sum();
return 0;
}

as here we are seeing that the different functions sum() and add() are modifying the value of the (global variable a).Also as the function sum() is being executed after add().So due to which the value of variable a gets changed before the execution of sum(). This actually the free flow of the data within the different functions.

This drawback is being removed by the object-oriented programming language which binds the data and functions together. This data and function bounded together was collectively known as object.


Read More

Top 5 C++ Manipulators Every Programmer Should Know

Posted by Utkarsh Jain 2 Comments
The main purpose of C++ manipulators is to format the output. These manipulators increase the enhance ability in the program.These manipulators allow the programmer to show data in different according to his wish. Some important manipulators used in C++ are as follows:

1: endl


2: setw

3: setprecision

4: showpoint

5: setfill


To use these manipulators in a program, iomanip.h shoud be included in the program. However one manipulator called endl can be used without adding that header file. And these manipulator functions are designed to be used in conjunction with the insertion(<<) and extraction(>>) operators. For example


cout<<endl;

'endl' Manipulator:

endl is probably the most used manipulator in C++. The word endl stands for end of line and it is used to move the cursor to the beginning of next line. It works similar to '\n' escape sequence and requires no parameter.

Syntax:

cout<<endl;

Example:

cout<<"Hello"<<endl<<"World";

The above line first prints "Hello" and then endl manipulator displays a new line and then "World" is printed on the next line.



'setw' manipulator:

The setw manipulator is used to display the value of an expression in specified columns. The value of expression can be string or number. If the value of expression is less than specified columns then the additional columns are left blank from left side. The word setw stands for set width.

Syntax:

setw(n)

The n indicates the number of columns in which the value is to be displayed. This specified width is just applied to the value that is inserted after it.

Example:

cout<<setw(10)<<"Hello"<<setw(10)<<"C++"<<setw(10)<<"World";


'setprecision' manipulator:


The setprecision manipulator is used to set the number of digits to be displayed after the decimal point. It is applied to all subsequent floating point numbers written to that output stream. The value is rounded with the use of this manipulator. This manipulator has no impact on integer type variables.

Syntax:

setprecision(n)

The n indicates the number of digits to be displayed after the decimal point.

Example:

float n=2.12345;

cout<<setprecision(6)<<n<<endl;

cout<<setprecision(5)<<n<<endl;

cout<<setprecision(4)<<n<<endl;

cout<<setprecision(3)<<n<<endl;





'showpoint' manipulator:


In C++, the decimal part of a floating-point number is not displayed if it is zero by default. The showpoint manipulator is used to display the decimal part even if the decimal part is zero. When this manipulator is set then all the floating values being used in that stream displays the trailing zeros after decimal point. There is also a noshowpoint manipulator which tells the compiler not to show decimal part if it is zero. The precision setting can be modified using the setprecision manipulator.

Syntax:

cout<<showpoint;

Example:

float a = 30;

cout<<showpoint<<a<<endl;

cout<<noshowpoint<<a;



'setfill' manipulator:


The setfill manipulator is used to replace the leading or trailing blanks in the output by the specified character. It requires one parameter to specify the fill character. The parameter can be a character constant , character variable or an integer that represents the fill character in ASCII system. The manipulator must be used with fixed width output.


Syntax:

setfill('c');

Here c indicates a character or its equivalent ASCII value.

Example:

cout<<setw(18)<<setfill('@')<<"Hello World"<<endl;

cout<<setw(18)<<setfill('+')<<"Hello World"<<endl;

cout<<setw(18)<<setfill('*')<<"Hello World"<<endl;




Author Bio


Kamal Choudhary is a tech geek who writes about c++ programming tutorials on C++ Beginner. He is a student of computer science in University of Gujrat, pakistan. He loves to write about computer programming. You can find his full bio here. Follow him on twitter @ikamalchoudhary
Read More

How We Can Have a Nested Return In a Function

Posted by Tushar Bedekar
Let us First Understand what is required and what the question is all about.Actually we are discussing about nested return in the function. that is return within the return  so follow is the programme which is conveying the same.Her we have taken the two function name "Factorial" and "Sum" which are calculating the factorial of a number and the result of the factorial  is returned to the function name sum which is calculating the sum of any number


#include <stdio.h>
#include <stdlib.h>

int factorial();
int sum();

int main(int a)
{
    int c;
    printf("\"enter the a number\"");
    scanf("%d",&a);

    c=sum(a);
    printf("The required result is %d \n",c);
    getchar();
    return 0;
}

int factorial(int y)
{
    int i,fact=1;
    for(i=1;i<=y;i++)
    fact=fact*i;
    printf("The factorial of a number is %d \n",fact);
    return fact;
}

int sum( int x)
{
    int result,k;
    printf("enter the number whose factorial is required \n");
    scanf("%d",&k);
    result=x+factorial(k);
    return result;
}

Read More

Difference Between Procedure Oriented Programming (POP) & Object Oriented Programming (OOP)

Posted by Tushar Bedekar

Procedure Oriented ProgrammingObject Oriented Programming
Divided IntoIn POP, program is divided into small parts called functions.In OOP, program is divided into parts called objects.
ImportanceIn POP,Importance is not given to data but to functions as well as sequence of actions to be done.In OOP, Importance is given to the data rather than procedures or functions because it works as a real world.
ApproachPOP follows Top Down approach.OOP follows Bottom Up approach.
Access SpecifiersPOP does not have any access specifier.OOP has access specifiers named Public, Private, Protected, etc.
Data MovingIn POP, Data can move freely from function to function in the system.In OOP, objects can move and communicate with each other through member functions.
ExpansionTo add new data and function in POP is not so easy.OOP provides an easy way to add new data and function.
Data AccessIn POP, Most function uses Global data for sharing that can be accessed freely from function to function in the system.In OOP, data can not move easily from function to function,it can be kept public or private so we can control the access of data.
Data HidingPOP does not have any proper way for hiding data so it is less secure.OOP provides Data Hiding so provides more security.
OverloadingIn POP, Overloading is not possible.In OOP, overloading is possible in the form of Function Overloading and Operator Overloading.
ExamplesExample of POP are : C, VB, FORTRAN, Pascal.Example of OOP are : C++, JAVA, VB.NET, C#.NET.
Read More

Header File In C Programming language

Posted by Tushar Bedekar
As We all know that in the C programming language we use to include the header files before staring the programming further. so lets view today what these header files mean to us.

As in the old programming IDE`s such as turbo c etc. we use to write as below
                          #include<stdio.h> 
#include<conio.h>        
These two are the basic header files that we usually include.There can be also different types of the header files such as<math.h>,<string.h>,<graphic.h>,<string.h>,user defined header files and many more depending on the type of the requirement in the program me written.now before moving further lets us first know what s header file.

What is Header File:-

A header file is a file with extension .h which contains C function declarations
and macro definitions and to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that come with your compiler.

You request the use of a header file in your program by including it, with the C pre-processing directive #include like you have seen inclusion of stdio.h header file, which comes along with your compiler.

Including a header file is equal to copying the content of the header file but we do not do it because it will be very much error-prone and it is not a good idea to copy the content of header file in the source files, specially if we have multiple source file comprising our program.

Include Syntax:-

Both user and system header files are included using the preprocessing directive #include. It has following two forms:
#include <file>
This form is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the -I option while compiling your source code.
#include "file"
This form is used for header files of your own program. It searches for a file named file in the directory containing the current file. You can prepend directories to this list with the -I option while compiling your source code.

Include Operation:-

The #include directive works by directing the C preprocessor to scan the specified file as input before continuing with the rest of the current source file. The output from the preprocessor contains the output already generated, followed by the output resulting from the included file, followed by the output that comes from the text after the #include directive. For example, if you have a header file header.h as follows:
char *test (void);
and a main program called program.c that uses the header file, like this:
int x;
#include "header.h"

int main (void)
{
   puts (test ());
}
the compiler will see the same token stream as it would if program.c read
int x;
char *test (void);

int main (void)
{
   puts (test ());
}
The Next Discussion Will Be on Introduction to a various types of header files in brief. so stay connected with us.Readers One Important note for you (if any one wants to share there articles with us on any topic please click the link belowWrite for Us
Read More

The Bulid Process

Posted by Tushar Bedekar
Before Going more with this topic let us first understand what it is? Basically it is a process which takes place in order to build the .exe (executable file) from the code written in the editor or any integrated development environment.

Here this article is in the reference to the "C and C++ programming language".

C Source Code:-

The code that you have written in the editor is referred to as a source code.In "C Programming" language this source code is stored with an .c extension and in that if the C++ programming language it is being stored with the .cpp extension.

This source code includes many user

  • User defined functions   
  • Many library functions 
  • Macros Definition
  •  And native codes
for more info please refer Source Code Vs Object Code



Pre-compilation:-

Now this is the  first step in build process.During this step the C source code is get expanded on the basis of pre processor directives included in the sources code. These pre processor directives may include 
  • #include
  • #define
  • #ifdef and #pragma etc. 
During this pre compilation process the source code that is being stored in the .c format is get converted into the .I extension which is referred as the expanded source code.for example the stored in the form of tushar.c format is get converted into the form of tushar.I format. that means we can say the during the pre compilation only the extension or the format of the code changes in the first step if the build process.

Compilation:-

The remaining content will be updated within 10 hrs. so stay connected

Read More

Can we write any thing inside the main function in c?

Posted by Tushar Bedekar
Image result for cyes we can write inside the main function.That is we can pass formal arguments inside the main function in c.we can declare any variable inside the main function which is same as declaring the variable inside the block of the main function. lets have a look on the program given below:




Program:-  

#include <stdio.h>
#include <stdlib.h>

int main(int a,int b)
{
    int c;
    printf("\"enter the two numbers\"");
    scanf("%d%d",&a,&b);
    c=a+b;
    printf("the sum of %d and %d is %d",a,b,c);
    getchar();
    return 0;
}

Have A Try:-

Can we Store Something in the void Data Type.If no then what is the purpose of using void as a modifier or a data type in "C Programming" languages.put your answer in the form of the comment.

you many also contact us at contact us
Email:-      admin@allaboutcomputing.net
Read More

Write a C program for Generating a pattern as given bellow

Posted by Tushar Bedekar
A B C D E F G F E D C B A
A B C D E F     F E D C B A
A B C D E            E D C B A
A B C D                   D C B A
A B C                           C B A
A B                                   B A
A                                          A






C Program me:-


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int l=6;
    int i,k,p=6,m=1;
    char ch,kp='F',tu;
    printf("ABCDEFGFEDCBA \n");
    for(i=0;i<=6;i++)
    {
        tu=kp;
        ch=('A'-1);
        for(k=0;k<l;k++)
        {
            ch=ch+1;
            printf("%c",ch);
        }

        for(k=0;k<m;k++)
            printf(" ");

        for(k=0;k<p;k++)
        {
           printf("%c",tu);
           tu=tu-1;
        }
        kp=kp-1;
        printf("\n");
        l=l-1;
        m=m+2;
        p=p-1;
    }

    return 0;
}

Read More

IDE,Linker,Editor,Console And Debugger

Posted by Tushar Bedekar
Basically If We talk About writing the "C Program-me" We usually use the IDES (Integrate Development Environment) such as Turbo C++,Dos box(specially for windows 7 and windows 8). More over one can also use online software's to compile and execute the c program-me.


Integrated Development Environment IDE:-


Basically place that we use to write the "C program-me" is referred to as the Integrated development environment (IDE).An integrated development environment (IDE) or interactive development environment is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of a source code editor, build automation tools and a debugger. Most modern IDEs offer Intelligent code completion features.


Linker:-



A linker or link editor is a computer program that takes one or more object files generated by a compiler and combines them into a single executable program.

Definition: To convert Source Code to Machine code takes two phases.
Compilation. This turns the Source Code into Object Code.
 Linking. This collects all the various Object Code files and builds them into an EXE or DLL.
Linking is quite a technical process. The obj files generated by the compiler include extra information that the linker needs to ensure that function calls between different obj files are correctly "joined up".


Editor:-



A text editor is used to edit plain text files.  Text editors differ from word processors, such as Microsoft Word or WordPerfect, in that they do not add additional formatting information to documents.  You might write a paper in Word, because it contains tools to change fonts, margins, and layout, but Word by default puts that formatting and layout information directly into the file, which will confuse the compiler.  If you open a .doc file in a text editor, you will notice that most of the file is formatting codes.  Text editors, however, do not add formatting codes, which makes it easier to compile your code.

Definition: 
An Editor is an program much like a Word Processor that you use to edit the Source Code of any program you write.

Most IDEs come with a built in editor and some will automatically highlight compile errors in the editor to simplify fixing them.


Console:-



(1) The combination of display monitor and keyboard (or other device that allows input). Another term for console is terminal. The term console usually refers to a terminal attached to a minicomputer or mainframe and used to monitor the status of the system.
(2) Another term for monitor or display screen.
(3) A bank of meters and lights indicating a computer's status, and switches that allow an operatorto control the computer in some way.
(4) A device specially made for game play called a video game console. The player interacts with the game through a controller, a hand-held device with buttons and analog joysticks or pads. Video and sound are received by the gamer though a television. See also console game.
(5) In Windows Home Server the Console is the application software you use to manage Windows Home Server from any of the computers on your home network. Here you can configure back-ups, access add-ins, configure folders, and change Windows Home Server settings.


Debugger:-



A special program used to find errors (bugs) in other programs. A debugger allows a programmer to stop a program at any point and examine and change the values of variables.

Most IDEs come with a built in editor and some will automatically highlight compile errors in the editor to simplify fixing them.


Read More

Top 20 "C" programs asked in interview.

Posted by Utkarsh Jain

Programs :


1. Write a program to find factorial of the given number...
2. Write a program to check whether the given number is even or odd.
3. Write a program to swap two numbers using a temporary variable.
4. Write a program to swap two numbers without using a temporary variable.
5. Write a program to swap two numbers using bit wise operators.
6. Write a program to find the greatest of three numbers.

7. Write a program to find the greatest among ten numbers.
8. Write a program to check whether the given number is a prime.
9. Write a program to check whether the given number is a palindrome c number.
10.Write a program to check whether the given string is a palindrome .
11.Write a program to generate the Fibonacci series.
12.Write a program to print"Hello World"without using semicolon anywhere in the code.
13.Write a program to print a semicolon without using a semicolon anywhere in the code.
14.Write a program to compare two strings without using strcmp() function.
15.Write a program to concatenat e two strings without using strcat() function.
16.Write a program to delete a specified line from a text file.
17.Write a program to replace a specified line in a text file.

18.Write a program to find the number of lines in a text file..
19.Write a C program which asks the user for a number between 1 to 9 and shows the number. If the user
inputs a number out of the specified range, the program should show an error and prompt the user for a
valid input.
20.Write a program to display the multiplication table of a given number..



Note:-

  • The Solution to the above question will be uploaded soon
  • The above question are as per the author point of view.the real questions may be different.

Read More

Top 20 Frequently asked questions in c programming

Posted by Tushar Bedekar

Top 20 "C" programs asked in interview,,.!!!

Programs :

1. Write a program to find factorial
of the given number...
2. Write a program to check whether the given number is even or odd.
3. Write a program to swap two numbers using a temporary variable.
4. Write a program to swap two numbers without using a temporary variable.
5. Write a program to swap two numbers using bitwise operators.
6. Write a program to find the greatest of three numbers.
7. Write a program to find the greatest among ten numbers.
8. Write a program to check whether the given number is a prime.
9. Write a program to check whether the given number is a palindrome c number.
10.Write a program to check whether the given string is a palindrome .
11.Write a program to generate the Fibonacci series.
12.Write a program to print"Hello World"without using semicolon anywhere in the code.
13.Write a program to print a semicolon without using a semicolon anywhere in the code.
14.Write a program to compare two strings without using strcmp() function.
15.Write a program to concatenat e two strings without using strcat() function.
16.Write a program to delete a specified line from a text file.
17.Write a program to replace a specified line in a text file.
18.Write a program to find the number of lines in a text file..
19.Write a C program which asks the user for a number between 1 to 9 and shows the number. If the user
inputs a number out of the specified range, the program should show an error and prompt the user for a
valid input.
20.Write a program to display the multiplica tion table of a given number..

Note:-The solution will be published shortly stay connected with us.
Read More
back to top