Rai Business School: Assignment
Rai Business School: Assignment
ASSIGNMENT
Subject: C++
Program: PM
Semester: 3
Question 1 . What is a programming language? Explain algorithm and flowchart with the help of
suitable examples.
Answer . Coded language used by programmers to write instructions that a computer can
understand to do what the programmer (or the computer user) wants. The most basic (called low-
level) computer language is the machine language that uses binary ('1' and '0') code which a
computer can run (execute) very fast without using any translator or interpreterprogram, but is
tedious and complex. The high-level languages (such as Basic, C, Java) are much simpler (more
'English-like') to use but need to use another program (a compiler or an interpreter) to convert the
high-level code into the machine code, and are therefore slower. There are dozens of
programming languages and new ones are being continuously developed. Also called computer
language.
Algorithm :
An algoritham is a finite sequence of well defined steps or operations for
solving a problem in
systematic manner . Instructions are written in the natural language like
English .It is also called
step by step solution.
Start
Sum = 0
I=1
I<=10
Print
“Sum=” , Sum
Read num
Stop
Sum = Sum + num
I=I+1
Maitrey Patel
Lecturer, C.E Department
4
Types of algorithm :
There are various types of algorithm exists , according to types of problem
appropriate types of
algorithm used .
_ Divide and conquer : In this technique , complex problems are divided in
several steps
or smaller problems , which make problem easy to solve .
_ Greedy method : In this method , there is problem with several possible
solutions .One
best solution is selected with help of this method .
_ Branch and bound : When there are several statement or certain part of
logic repeated ,
this type of technique is used .
_ Recursion : when procedure call itself is called recursion .
_ Effectiveness : All operations can be carried out in predefined time and
sequence .
Advantages :-
_ Very easy to write .
_ Easy technique to understand logic .
_ Easy identification of the mistakes by non computer person .
Disadvantages :-
_ Time consuming .
_ Difficult to show branching and looping .
_ Large programs are difficult to put in algoritham.
Example of algoritham :
Write an algoritham to store sum of 10 different numbers .
Step 1 : sum = 0
Step 2 : I = 1
Step 3 : repeat step 3 through step 6 until I <= 10.
Step 4 : read num
Step 5 : sum = sum + num
Step 6 : I = I + 1
Maitrey Patel
Lecturer, C.E Department
5
Step 7 : print “total=” , sum
Step 8 : stop.
Flowcharts :
_ A Flowcharts is graphical or diagrammatical representation of sequence
of any problem
to be solved by computer programming language .
_ The flow charts are prepared in the early stage of program development .
They are useful
in understanding the logic of complicated and lengthy problems . After
drawing
flowchart it become easy to write any program .
_ There are various standard symbols available to represent logic of problem
which are as
follows :
Advantages :
- Easy to draw .
- Easy technique to understand logic .
- Easy to find errors by non-technical person .
- Easy for branching and looping .
Condit
Disadvantages :
- Time consuming .
- Difficult for modification .
- For large programs , it is difficult to draw flow charts .
Example :
Draw a flow to do the sum of 10 elements read from user .
start
SUM=0
I=1
I<=
10
Print
“SUM= Read
Sum=Su
“,SUM num
m+NUM
Stop
I=I+1
Question 2. What is Object Oriented Programming language? How is it different from procedural
language?
Question 3. What are the different data types available in ‘C’ language? Explain in detail.
A programming language is proposed to help programmer to process certain kinds of data and to
provide useful output. The task of data processing is accomplished by executing series of
commands called program. A program usually contains different types of data types (integer,
float, character etc.) and need to store the values being used in the program. C language is rich of
data types. A C programmer has to employ proper data type as per his requirement.
C has different data types for different types of data and can be broadly classified as :
Data Types in C
Integers are whole numbers with a range of values, range of values are machine dependent.
Generally an integer occupies 2 bytes memory space and its value range limited to -32768 to
+32767 (that
is, -215 to +215-1). A signed integer use one bit for storing sign and rest 15 bits for number.
To control the range of numbers and storage space, C has three classes of integer storage namely
short int, int and long int. All three data types have signed and unsigned forms. A short int
requires half the amount of storage than normal integer. Unlike signed integer, unsigned integers
are always positive and use all the bits for the magnitude of the number. Therefore the range of
an unsigned integer will be from 0 to 65535. The long integers are used to declare a longer range
of values and it occupies 4 bytes of storage space.
The float data type is used to store fractional numbers (real numbers) with 6 digits of precision.
Floating point numbers are denoted by the keyword float. When the accuracy of the floating
point number is insufficient, we can use the double to define the number. The double is same as
float but with longer precision and takes double space (8 bytes) than float. To extend the
precision further we can use long double which occupies 10 bytes of memory space.
Character Type:
Character type variable can hold a single character. As there are singed and unsigned int (either
short or long), in the same way there are signed and unsigned chars; both occupy 1 byte each, but
having different ranges. Unsigned characters have values between 0 and 255, signed characters
have values from –128 to 127.
Example: a, b, g, S, j.
Void Type:
The void type has no values therefore we cannot declare it as variable as we did in case of
integer and float.
The void data type is usually used with function to specify its type. Like in our first C program
we declared “main()” as void type because it does not return any value. The concept of returning
values will be discussed in detail in the C function hub.
Array in C programming
An array in C language is a collection of similar data-type, means an array can hold value of a
particular data type for which it has been declared. Arrays can be created from any of the C data-
types int,...
Pointers in C Programming
In this tutorial I am going to discuss what pointer is and how to use them in our C program.
Many C programming learner thinks that pointer is one of the difficult topic in C language but its
not...
Structure in C Programming
We used variable in our C program to store value but one variable can store only single piece
information (an integer can hold only one integer value) and to store similar type of values we
had to declare...
C language supports a feature where user can define an identifier that characterizes an existing
data type. This user defined data type identifier can later be used to declare variables. In short its
purpose is to redefine the name of an existing data type.
Syntax:typedef<type><identifier>; like
typedefint number;
Now we can use number in lieu of int to declare integer variable. For example: “int x1” or
“number x1” both statements declaring an integer variable. We have just changed the default
keyword “int” to declare integer variable to “number”.
Answer .
#include<stdio.h>
#include<conio.h>
Void main ()
{
Char str[10],rev str[10];
Int i ,m=0,n;
Printf(“enter any string”);
Scanf (“%S”,str);
For(i=0;str[i]!=’\0’, i++);
N=i ;
i--;
For(; i>=0; i=0; i--)
{
Rev str[m]=str[i];
m++;
}
Rev str[i]=’\0’;
For(i=0;str[i]!=’\0’;i++)
{
ifstr[i]==rev str[i])
{
Printf (“NO Palindrome”);
}
}
if(i>=n)
printf (“paliandrome”);
}