Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C Programme

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

Program:-

A program is a set of instruction to carry out some specific job in a computer. Program
should be able to give meaningful information. An instruction is a command or expression to
perform any specific job.

Programming language:
Programming language is defined as a set of rules that perform some specific task. It is also
known as computer programming language. There are different types of programming language.

Programming Language

Lower Level High Level

Procedural Oriented Language


Machine Level
Problem Oriented Language

Assembly Level Natural Language

Fig:- Programming Language

Algorithm:-
Algorithm is a set of step by step instructions to solve any particular problem. Some of
the major guidelines while writing an algorithm are as follows:-
 The number of instructions should be finite.
 It should have input, process and output after operate execution of algorithm.
 Each instruction should be in simple language and no ambiguous instructions should be
included.
 It should not be depended on any program language or computer.

Advantages of Algorithm:-
1) It is simple and easy to understand.
2) There is no any hard and fast rule for writing an algorithm.
3) It does not require any prior knowledge for programming at the time of writing algorithm.
4) It is easy for coding.

1
Disadvantages of Algorithm:-
1) It is difficult for translating algorithm into program.
2) It is not considered as standard tool for program designing.

Flow-chart:-
Flow-chart is a diagrammatic representation of an algorithm. It is a second step of
programming tools. We can represent different symbols in flow-chart.

Types of flow-chart:-
1) Program Flow-chart
2) System Flow-chart
The explanations of above points are as follows:-
1) Program Flow-chart:-
A program flow-chart is commonly used flow-chart for serving small size logical
problems. It also helps for the effective solution of mathematical problem. It defines step by step
sequence of operation and the flow of operation of a problem. It is very effective tools for
understanding, designing and debugging of a problems. It shows the internal relationship
between the instructions.

Different symbols used in Program Flow-chart:-


Symbols Meaning
Start/end symbols

Input/output symbols

Processing symbol

2
Flow line symbol

Decision symbol

Comment symbol

Connector symbol

Output

Input

2) System Floe-chart:-
It is used to show operation of a large size real world problem. It helps to show the board
overview of the data flow and the sequence of operation in an organization. It helps for
designing of a system and to show business problem.

Different symbols used in System Flow-chart:-


Symbols Meaning
Sequential access storage

Magnetic storage

3
Data storage

Manual input

Document

Introduction of C language:-
C programming is a popular computer programming language which is widely used for
system and application software. It is general purpose computer language. It was developed by
Dennis Ritchie in 1972 at bell Laboratory. It has facilities for structure programming. It is a high
level programming language. Compliers are available for the majority of available computer
architectures and operating systems. It is widely used professional language for various reasons
which are given below:-
1) It is easy to learn.
2) It is a structure language.
3) It produces efficient programs.
4) It can handle low level activities.
5) It can be complied on a variety of computer plat forms.

Advantages of C Language:-
1) It is easy debugging, testing and maintaining.
2) It is portable.
3) It is fast for executing.
4) It is flexible.
5) It is easy to remember keywords.
6) It is compact programming language.
7) It has ability to extend itself.

4
8) It has rich set of operator.
9) Dynamic storage location is possible.
10) Complier is easily available.

Disadvantages of C language:-
1) There is no strict tight checking.
2) No run time checking.
3) Difficult to fix the bugs.
4) It does not support modern program.

Different Versions of C:-


1) Turbo C
2) Borland
3) Code lite

Complier:-
Those types of software which are used to translate code written in high level language into
machine level language as a whole instructions at a time is known as complier. In C language,
Complier is used to translate code into machine level language.

Complier
High Level Language Machine Level Language

Interpreter:-
Those types of software which are used to translate code written in high level language
into machine level language one instruction at a time is known as interpreter.

Interpreter
High Level Language Machine Level Language

Assembler:-
Those types of software which are used to translate mnemonic codes written in
assembly level language into machine level language are known as assembler.

5
Comments:-
Comments are the statements that are used for user aid.
Mainly there are two types of comments. They are given below:-
1) Single Line Comments
2) Double Line Comments

Header Files:-
Header files contain definition of function and variable which can be incorporated into
any C program by using the pre-processor # include statement. To use any of the standard
functions, the appropriate header file should be included. All header files have extension .h.

Variable:-
A variable is a value that can be changed at the time of program execution at any time.
It is a memory location used to store a value. A variable name should be carefully chosen by the
programmer so that its use is reflected in a useful way in the entire program.

Types of variable:-
There are mainly two types of variable which are given below:-
1) Numeric Variable
2) String Variable
The explanations of above points are as follows:-

1) Numeric Variable:-
Those types of variable which stores numeric data only are known as numeric variable.
The numeric values may be whole numbers or fractional numbers. For :- example 15, 16, 18,
15.5, 18.5, 13.3, 15.5123, 16.12654 etc.

2) String Variable:-
Those types of variable which stores character data only are known as string variable. The
string variable may be single character or string. For example:- character, array of character etc.

Constants:-
Constant is the fixed value that does not change during the execution of program.
C supports four types of constant. They are character, string, integer, and float. The integer and
floating point constant represent numbers. They collectively knew as numeric type constant.

Types of Constant:-
6
1) Character Constant
2) String Constant
3) Integer Constant
4) Floating Point Constant
The explanations of above points are as follows:-
1) Character Constant:-
Character constant is a single character which is enclosed with single quotation marks.
Some valid character constants are ‘A’, ‘x’, ‘5’, ‘10’ etc.

2) String Constant:-
String constant consists of combination of two or more than two characters. It enclosed
by double quotation marks. For example:- ‘A’, ‘X’, ‘5’ etc.

3) Integer Constant:-
Integer constant refers to a sequence of digits that will be either positive or negative. For
example:- 235, -657, 789 etc.

4) Floating Point Constant:-


Floating point constant is a base ten numbers that contains either a decimal point or an
exponent. For example:- 2.10, 0.2, 1.535E+8 etc.

Key words:-
It is used to create a new name for an existing data type. C language allows user to define
their own data types which are based on existing data type.

Operators:-
Operators are the symbols which helps user to command the computer to do a certain
mathematical or logical manipulation. Operators are used in C language to operate on data and
variables.

Types of Operators:-
1) Arithmetic Operators
2) Relational Operators
3) Assignment Operators
4) Logical Operators
5) Unary Operators (Increment or Decrement Operators)
6) Conditional Operators (Ternary Operators)

7
7) Comma Operators
8) Bitwise Operators
9) Size of Operators
The explanations of above points are as follows:-
1) Arithmetic Operators:-
Those types of operators which are used to perform mathematical operators are known
as Arithmetic Operators. For example:- +, -, *, /, % etc.

2) Relational Operators:-
Those types of operators which are used compare two different operands are known as
Relational Operators. For example:- <, <=, >, >=, <>, != etc.

3) Assignment Operators:-
It is used to assign a value a variable. Its form is as follows:-
Operator Statement Example
+= a+=1 a=a+1
-= a-=1 a=a-1
*= a*=1 a=a*1
/= a/=2 a=a/2
%= a%=b a=a%b
4) Logical Operators:-
These operators are used to give logical value either true or false. C has the given logical
operators such as
Operator Symbol Example
AND && (a>b)&&(a>c)
OR .. (a>b) .. (a>c)
NOT ! !(a==b)

5) Unary Operators:-
These types of operators can take a single operand. These act upon single
operand to be incremented or decremented by one.
Operator Symbol Action Example
Increment ++ Increment by one ++aa, a++
Decrement -- Decrement by one --a, a--

6) Conditional Operators:-

8
Those are the new important features of C language which are used to check certain
relational expression and execute the true statement. If the condition is true and display the
false statement if condition is false. Commonly it uses two symbols question mark (?) and the
colon (:). But, not together as in >=, <= etc.

7) Comma Operators:-
The comma operators use in different ways:-
a) These are used in variables declaration.
b) These are used in linked list of expression such as C=(a=10, b=20, a+b)
c) These are used for loop.

8) Bitwise Operators:-
The bitwise operators are used for having bit level computation of different values.
Operators Meaning
& Bitwise AND
. Bitwise OR
^ Bitwise exclusive OR
>>/<< Shift cells right/left
9) Size of Operators:-
The size of operators written the number of bytes occupied in the memory.
For example:-
m= size of (int), // value of m will be 2.
n= size of (long int), // value of will be 4.

Control Statement:-
The statement which alters the flow of execution of the program is known as control
statement. There are two types of control statement. They are:-
a) Loop or Repeating statements
b) Decision Making statements

If Else:-
In two way branching statement, if expression is true, then true statement will execute.
Otherwise false statement will execute.

Switch Statement:-

9
It allows us to select a choice out of many available choices. The switch statement causes
a particular group of statements to be chosen from several available groups. The selection is
based upon the current value of an expression that is included within the switch statement. A
switch statement is more structured way to express conditional logic in C language.

While Statement:-
It executes program statement repeatedly until the given condition is true. It checks
condition at first, if it is found true, then it executes the statement written in its body part.
Otherwise it just gets out from the loop statement. It is also known as pre-test loop.

For loop:-
It is useful to execute the statement for a number of times, when the number of
repetition known in advance, the use of this loop will be more effective.

Do while loop:-
It executes program statement repeatedly until the given condition is true. It executes
the program statement once at first the only condition is checked. If condition is found true,
then it executes the program statement again. Otherwise it gets out from the loop statement.

Array:-
An array is a group of related data items that shares a common file or
An array is a data structure that stores a number of data items as a single entity (object). The
individual data items are called elements. It contains finite numbers of homogeneous elements
or items.

Advantages of Array:-
1) Easy to handle similar type of data in a program.
2) Efficient for solving problems like sorting, searching, and indexing.
3) Easy to solve matrices relating problem.
4) Easy to manipulate graphics types of problem.

Disadvantages of Array:-
1) Not possible to hold dissimilar type of data in array.
2) Difficult to visualize the multi dimensional areas.
3) Difficult to define the size of array during running time.

10
Array Declaration:-
Syntax:-
data _type array_name [expression];
where,
data_type It is a type of element store in array.
array_name Name of array.
expression Number of positive array elements.
Types of Array:-
Mainly there are two types of array which are given below:-
1) One Dimensional Array
2) Two Dimensional Array
The explanations of above points are as follows:-

1) One Dimensional Array:-


An array which has only one sub script is known as one
dimensional array. A sub script is a number of large bracket in which we put the size of array.
Syntax:-
data_type arrayu_name [array-size];
2) Two Dimensional Array:-
An array which has more than one sub script is known as two
dimensional arrays. Two dimensional arrays will require two square brackets, one for row size
and another for column size. The maximum capacity of elements of array is the product of row
size and column size. Three dimensional arrays will require three square brackets and so on.
Syntax:-
data_type array_name [row size] [column size];

Function Declaration:-
It specifies function name, argument type and return value.
Syntax:-
return_value function_name (arg 1, arg 2,………..arg n);

Function:-
a function is defined as a self contain block of statements that performs a
particular task or job. This is a logical unit composed of a numbers of a statements group into a
single unit. A C program consists of one or more than one functions. Execution of every C
program always begins with main ().

11
Additional functions will be subordinated to main and perhaps to one another.
After each function has done, its operation control returns back to the main. The remaining
statements of main are executed.
If a program contains multiple functions, their definitions may appear in any order and
independent of one another.

Advantages of Function:-
1) The length of square program can be reduced using function.
2) It makes possible top down modular program.
3) It increases code reusability
4) The program development will be faster.
5) The program debugging will be easier.
6) Large number of programmer can be involved.
7) It has logical clarity.
8) Program can be creating short period of time.

String:-
String functions are the functions which are used to write the length of given string.
These functions argument must be enclosed by parenthesis.

Types of String Function:-


1) Strlen ()
2) Strcat ()
3) Strcpy ()
4) Strcmp ()
5) Strrev ()
The explanations of above points are as follows:-
1) Strlen ():-
This function is used write the length of given string. The length of string is the number of
character.
Syntax:-
integer_variable=strlen(string);

2) Strcat ():-

12
This concatenates two strings. This function accepts two strings as parameters and stores
the content of the second string at the end of the first.
Syntax:-
strcat (string 1, string 2);
3) Strcpy ():-
This function copies one string to another. The function accepts two strings as parameter
and copies the second string character by character into the first one up to an including the null
character of the second string.
Syntax:-
strcpy (destination_string, source_string);
4) Strcmp ():-
This is used to compare two strings character by character by string variable or constant.
Syntax:-
strcmp(string1,string2);
5) Strrev ():-
This function is used to reserve all character in a string except characters at the end of
string.
Syntax:-
strrev(string);

Pointer:-
A pointer is a variable that points to another variable which means it contains the
memory address (location) of another variable and is declared as the pointer type. It is very
powerful variable which is used to directly deal with memory of computer. It is denoted by
asterisk sign ‘*’ and has to be declared in the similar way as we declare other variables.

Advantages of Pointer:-
1) It allows us to pass variables, array, functions, srtings, and structures as function arguments.
2) Commonly these are useful for handling the data table.
3) It helps to increase the execution speed.
4) It reduces the length and complexity of a program.
5) It supports dynamic memory allocation and reallocate of memory arguments.

Structure:-

13
A structure is a collection of variables under a single name. These variables can be of
different types and each has a name which is used to select it from the structure. The variables
are called member of structure. A structure is a convenient way of grouping several pieces of
related information together.
It is a data type which helps us to collect various types of data items having same name.
It is the tool which helps the programmer for handling the group of logically related data items.

Data File (File Handling):-


A data file is defined as the collection of data or information which is permanently stored
in secondary memory as a single unit. We can read, write, append, and delete data in data file as
per our requirement. C programming has different types of library function for creating and
managing data file.

14
Visual basic programming:-
In computer, a visual programming language is any programming language that lets users
create programs by manipulating program elements graphically rather than by specifying them
textually. A VPL allows program with visual expressions, spatial arrangement of text and graphic
symbols used either as element of syntax or secondary notation. For example, many VPLs(known
as dataflow or diagrammatic program) are based on the idea of “boxes and arrows’’, where
boxes or other screen objects are treated as entities, connected by arrows, lines or arcs which
represent relations.
Visual may be further classified. According to the type and extent of visual expression
used, into icon-based languages, and diagram languages. Visual programming environment
provide graphics or iconic elements which can be manipulated by users in an interactive way
according to some specific spatial grammar foe program construction.
Types of project in.NET:-
The following are some of the points of different projects that can be created with Visual
studio.NET:-
1. Console application
2. Windows application
3. Web services
4. Class library
5. Windows control library
The explanations of the above points are as follows:-

1. Console application:-
Console applications are light weight programs run inside the command prompt
(DOS) windows. They are commonly used for test application.

2. Windows application:-
Windows applications are form based standard windows desktop application for
common day to day tasks. (Ex: Hotmail and Google).
3.
4. Web service:-
5. Web application are programs that used to run inside some web server (EIIS) to
fulfill the user requests over the http.(Ex: Hotmail and Google).
6. Class library:-
7. Class library contain components and libraries to be used inside other
application. A class library cannot be executed and thus it does not have any entry point.
8.
9. Windows control library:-

15
10. Windows control library contains user defined windows controls to
be used by windows application.
11.
12. Different IDE of VB.NET:-
13. Menu bar and tool bar
1. Solution Explorer
2. Form designer
3. Output window
4. Object browser
The explanations of the above points are as follows:-
Menu bar and tool bar:-
Menu bar is a visual.net 2008 consists of the commands that are used for constructing a
software code. These commands are listed as menus and sub menus.
Menu bar also includes a simple Toolbar that lists the commonly used commands as buttons.
This Toolbar can be customized, so that the buttons can be added as required.
2. Solution explorer/ toolbar properties:-
Solution explorer allows you to view items and perform items management tasks in a solution
or a project. It also allows you to use the visual studio editors to work on files outside the
context of a solution or project.

Method and event:-


A method is a procedure created as a member of a class and they cause an object to do
something. Methods are used to access or manipulate the characteristic of an object or a
variable. There are mainly two categories of method you will use in your classes:-
 If you are using a control such as one of those provided by the Toolbox, you can call any of its
public methods. The requirements such a method depend on the class being used.
 If none of the existing method can perform desired task, you can add a method to a class.

An event is a signal that informs an application that something important has occurred. For
example, when a user clicks a control on a form the form can raise a Click event and call a
procedure that handles the event. There are various types of events associated with a Form like
click, double click, close, load, resize etc.

Variable:-
The computer memory is made of small storage areas used to hold the things that a program
needs while it is running. As a programmer, you specify this things, or you provide them to the
computer, the computer then puts them in these storage areas. When you need one of them,
you let the computer know. The machine located it and makes it available you to you used as
you see fit.

16
Variable are values you are asking the computer to store in its memory while the
program is running.
Using a variable:-
As stated already, a variable is an area of computer memory you use in your program. To
use a variable, you must give it a name. There are rules you should, and usually must, follow
when naming your variables. The name of a variable:-
 Must begin with letter
 Cannot have a period (remember that we use period to set a property, in words the period is an
operator)
Once a variable has a name, you can use it as see fit. For example, you can assign it a value and
then use the variable in your program as if it represented that value.

Data type:-
Before declaring or using a variable, first decide what kind of role that variable will play in
your program. Different variables are meant for different situations. The kind of variable you
want to use is referred to as a data type. To specify the kind of variable you want to use, you
type the As keyword on the right side of the variable’s name. the formula of declare such a
variable is:
Dim VariableName As Datatype
Types of data type:-
1. String

ORDER By command Author:-


This command is to select the entire field from report, you need to create query to
retrieve the information from the database. Here, we will use SQL to create the query. First of
all, right click on my connection to add a command to the data environment. The default
command is command 1; you can rename it as My command.

Concept of report in VB:-


Report is important and useful in many respects because they provide useful and
meaningful information concerning a set of data. Fortunately, Microsoft has integrated a good
writer into Visual Basic 6, so you no longer need to use Crystal report.
17
Steps to connect data adopter and data set with OLEDB:-
 Add a DataGridView control button in the form.
 Change the text on the button control to ‘Fill’
 Double click on the button control to add the required code for the click event of the button, as
shown below:

Imports System.Data.SqlClient
Public Class Form 1
Private Sub Form1 Load (sender As Object, As Event Args)
Handles My Base. Load
“TODO: This line of code loads into the ‘TestDBDataSet.CUSTOMERS’table. you can move, or
remove it, as needed.
Me.CUSTOMERSTableAdopter.Fill(me.TestDBDataSET.CUSTOMERS)
Set the caption bar text of the form.
Me.Text=”tutorialspoint.com”
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs)Handles Button1. Click


Dim connection As SqlConnection=New sqlconnection()
Connection.ConnectionString=Data Source=KABIR-DESKTOP;_
Initial Catalog=testDB;Integrated security= True”
Connection.Open()
Dim connection As SqlConnection=New sqlDataAdopter_
(“select*from Customer”,connection)
Dim ds As DataSet=New Datatype()
Adp.Fill(ds)
DataGridView.DataSource=ds.Tables(0)
End Sub
End Class

Data provider:-
A data provider used for connecting to a database, executing commands and retrieving
data, storing it in a dataset, reading the retrieved data and updating the databases.

Objects of Data provider:-


1. Connection
2. Command
18
3. Data Reader
4. Data Adopter
The explanations of the above points are as follows:-
1. Connection:-
The component is used to set up a connection with a data source.
2. Command:-
A command is a SQL statement or a stored procedure used to receive, insert, delete or modify
data in a data source.
3. Data Reader:-
Data reader is used to retrieve data from a data source in a read-only and forward-only mode.
4. Data Adapter:-
This is integral to the working of ADO.Net since data is transferred to and from a database
through a data adopter. It retrieves data from a database into a dataset and updates the
database. When changes are made to the dataset, the changes in the database are actually done
by the data adopter.

Data set:-
Data type is an in-memory representation of data. It is a disconnected, cached set of record
that is retrieved from a database. When a connection is established with a database, the data
adopter creates a dataset and stores data in it. After the data is retrieved and stored in a
dataset, the connection with the database is closed. This is called the ‘disconnected
architecture’. The dataset works as a virtual database containing tables, rows, and columns.

Components of Data set:-


1. Data table connection:-
2. Data relation collection
3. Extended properties
4. Data table
5. Data relation
6. Data row collection
7. Data view
8. Primary key
9. Data row
10. Data column collection
11. Data column
The explanations of the above points are as follows:-
1. Data table connection:-
It contains all the tables retrieved from the data source.
2. Data relation collection:-

19
It contains the relationship and the link between tables in a data set.
3. Extended properties:-
It contains additional information, like the SQL statements for retrieving data, time of retrieval,
etc.
4. Data table:-
It represents a table in the data table collection of a dataset. It consists of the data row and
data column objects. The data table objects are case sensitive.
5. Data relation:-
It represents a relationship in the data relationship collection of the dataset. It is used to relate
two data table to each other through the data column objects.
6. Data row collection:-
It contains all the row in the database.
7. Data view:-
It represents a fixed customized view of a data table for sorting, filtering, searching, editing and
navigation.
8. Primary key:-
It represents the column that uniquely identifies a row in a data table.
9. Data row:-
It represent a row in a the datatable. The data row object and its properties and method are
used to retrieve, evaluate, insert, delete, and update values in the data table. The
10. Data column collection:-

20

You might also like