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

MVPS’s

RAJARSHI SHAHU MAHARAJ POLYTECHNIC,


NASHIK

DEPARTMENT OF INFORMATION TECHNOLOGY

ACADEMIC YEAR 2019-2020

“Programming in C”

(22226)

MICROPROJECT

ON

“HUMAN CALCULATOR”

GUIDED BY

Mrs. S. S. Tile

1
MAHARASHTRA STATE BOARD OF TECHNICAL
EDUCATION

Certificate

This is to certify that Ms./Mr. ________________________________________

Roll No._______ of second semester of diploma in Information Technology of

Institute MVPS’s Rajarshi Shahu Maharaj Polytechnic, Nashik (Code:

1002) has successfully completed micro-project in Programming in C (22226)

for academic year 2019-20 as prescribed in curriculum of MSBTE, Mumbai.

Place: Nashik Enrollment no:1910020182

Date:…………. Exam seat no: 440848

Mrs. S. S. Tile Mr. T. K. Thange Dr. D. B. Uphade


Course Teacher/Guide H.O.D Principal

Seal of
institute

2
SUBMITTED BY

SR. NO Roll No ENROLLMENT EXAM SEAT NO STUDENT NAME


NO
1 1 1910020176 440842 PRATHAMESH AHER

2 2 1910020177 440843 SAKSHI AHER

3 3 1910020178 440844 AYUSH ADHAV

4 4 1910020179 440845 NIKITA AHIRE

5 5 1910020180 440846 YOGESH BAVISKAR

6 6 1910020181 440847 NETRA BENDKULE

7 7 1910020182 440848 ANJALI BHAMARE

8 8 1910020183 440849 OM BHAMARE

3
INDEX

SR.NO. CONTENT PAGE NO.

1) Abstract 6
Chapter no.1
2) (Introduction) 7

Chapter no.2
3) (Coding and their output) 12

Chapter no.3
4) 15
(Algorithm & Flowchart)
5) Conclusion
19
6) References 20

SR.NO. TABLE NAME / PICTURE NAME PAGE NO.

1 Syntax of Function 7

4
2 Difference of function 8
3 Syntax of Switch Case 10
4 Output of calculator 14

LIST OF FIGURE

ABSTRACT
5
Our micro project based on the Human calculator. We have use many concept
like function, Do while loop, switch case etc. This project is user friendly and can easily be
understood by the user. In the coding section of this project we define the detail coding of
our project & we also paste the screen shot of basic coding. The whole project is developed
in C programming language, different variables and strings have been used for the
development of this project .this is a mini project so it contains a bit less features. it is easy
to operate and understood by users .this project can help students understand the operations
that are involved in designing Calculator software.
We will see that the C is the basic for creating program. Nowadays programs
are most important. Everyone knows about program. So, we will see that the development
of program help of various syntax. C helps you to understand working of a program and to
enhance your Programming logic. It also helps to visualize working of the computer.

Chapter No. 1
INTRODUCTION
6
C is the general purpose structured programming language designed and
written by the Dennis Ritche at AT & T’s Bell Laboratories of USA in 1972. C is a
middle level language because it combines both the features of high –level language and
low level language. C helps you to understand working of a program and to enhance your
Programming logic. It also helps to visualize working of the computer.

 Syntax that we used:-

1. Function

 Definition:-

A function is a group of statements that together perform a task. Every C program has
at least one function, which is main(), and all the most trivial programs can define additional
functions. You can divide up your code into separate functions. How you divide up your
code among different functions is up to you, but logically the division is such that each
function performs a specific task. A function declaration tells the compiler about a
function's name, return type, and parameters. A function definition provides the actual body
of the function. The C standard library provides numerous built-in functions that your
program can call. For example, strcat() to concatenate two strings, memcpy() to copy one
memory location to another location, and many more functions. A function can also be
referred as a method or a sub-routine or a procedure, etc.

 Syntax:-

Fig No.1.1 Syntax of Function

 Difference between function declaration & function definition:-

7
Function Declaration Function Definition

A prototype that specifies the function name,


Actual function that specifies the function
return types & parameters without the function
name, return types and parameters with the
body.
function body.

Helps to write what the function should


Indicates the compiler about the function and
perform. It is actual implementation of the
how to all that function.
function.

Contains the function name, parameters list, Contains the function name, parameter list,
return type return type, function body.

Table No.1 Difference of function

 Need of function in c program:-

A function is a block of statements that performs a specific task. Suppose


you are building an application in C language and in one of your program, you need
to perform a same task more than once. In such case you have two options –
a) Use the same set of statements every time you want to perform the task
b) Create a function to perform that task, and just call it every time you need to
perform that task.

 Parameter used in c :-

There are two types of parameter in c:-


a) Actual parameter:-
The parameters that appear in function calls called as Formal parameters: The
parameters that appear in function declarations.
For example:

#include <stdio.h>
int sum(int a, int b)
{
int c=a+b; return c;
}
int main( )
{
int var1 =10; int var2 = 20;
int var3 = sum(var1, var2);
printf("%d", var3);
return 0;
}

b) Formal parameter:-
These variables are called the formal parameters of the function. Formal
parameters behave like other local variables inside the function and are created upon

8
entry into the function and destroyed upon exit. While calling a function, there are
two ways in which arguments can be passed to a function 

 Types of function :-

There can be 4 different types of user-defined functions, they are:

 Function with no arguments and no return value.


 Function with no arguments and a return value.
 Function with arguments and no return value.
 Function with arguments and a return value.

1: Function with no arguments and no return value:-

Function with no argument means the called function does not receive any data from


calling function and Function with no return value means
calling function does not receive any data from the called function.

2: Function with no arguments and no return value:-

Function with no argument means the called function does not receive any data from


calling function and Function with no return value means
calling function does not receive any data from the called function.

3: Function with arguments and no return value:-

Here function will accept data from the calling function as there are
arguments, however, since there is no return type nothing will be returned to the
calling program. So it’s a one-way type communication.

4: Function with arguments and a return value:-

Function with arguments and one return value means both the calling function and
called function will receive data from each other. It’s like a dual communication.

2. Switch case:-
 Definition:-
9
A switch statement tests the value of a variable and compares it with multiple
cases. Once the case match is found, a block of statements associated with that particular
case is executed. Each case in a block of a switch has a different name/number which is
referred to as an identifier. The value provided by the user is compared with all the cases
inside the switch block until the match is found. If a case match is found, then the default
statement is executed, and the control goes out of the switch block.
 Syntax:-

Fig No.1.2 Syntax of Switch Case

 Need of Switch Case in c program :-


i. A switch is a decision making construct in C.
ii. A switch is used in a program where multiple decisions are involved.
iii. A switch must contain an executable test-expression.
iv. Each case must include a break keyword.
v. Case label must be constants and unique.

10
2. Do while loop:-
 Definition:-

The do while loop is exit controlled loop. That is the condition is the checked at
the end of loop. Hence even if the condition does not satisfy, the loop statements will
be executed at least once.

 Syntax:-
do
{
Statement 1;
}while(condition 1);

11
Chapter No. 2
CODING & THEIR OUTPUT

 C Program developed for Calculator:-

#include <stdio.h>
#include<conio.h>

Void display (int n1, int n2,char ch, int result );


Void add(int n1, int n2);
Void sub(int n1, int n2);
Void mult(int n1, int n2);
Void div(int n1, int n2);
Void rem(int n1, int n2);

Void main()
{
int ch;
int n1, n2;
char c;
clrscr;
do
{
printf("\t\t\t ----------------------------------------------------\n");
printf(“\t\t\t WELCOME TO SIMPLE CALCULATOR\n");
printf("\t\t\t ----------------------------------------------------\n");
printf("\t\t\t Enter first number\n");
scanf("%d", &n1);
printf("\t\t\t Enter second number\n");
scanf("%d", &n2);
printf("\t\t\t ----------------------------------------------------\n");
printf("\t\t\t Menu of Calculator\n");
printf("\t\t\t 1.Addition\n");
printf("\t\t\t 2.Subtraction\n");
printf("\t\t\t 3.Multiplication\n");
printf("\t\t\t 4.Division\n");
printf("\t\t\t 5.Remainder\n");
printf("\t\t\t Enter your choice:\n");
printf("%d",&ch);
switch(ch)
{
case '1':
add(n1, n2);
break;

12
case '2':
sub(n1, n2);
break;

case '3':
mult (n1, n2);
break;

case '4':
div(n1, n2);
break;

case '5':
rem(n1, n2);
break;

default:
printf ("\t\t\t\Please enter the correct input\n");
}
printf(“\t\t\t Do you want to continue?(y/n)\n”);
scanf(“%c”,&c);
printf("\t\t\t ----------------------------------------------------\n");
}while(getch()==’y’||getch()==’Y’);
printf(“\t\t\t Thanks for using Calculator\n”);
getch;
}

Void display (int n1, int n2,char ch, int result );


{
printf(“\t\t\t %d %c %d=%d\n”,n1,ch,n2,result);
}

Void add(int n1, int n2);


{
int result= n1+ n2;
display(n1,n2,’+’,result);
}

Void sub(int n1, int n2);


{
int result= n1- n2;
display(n1,n2,’-‘,result);
}

Void mult(int n1, int n2);


{
int result= n1* n2;
display(n1,n2,’*’,result);
}

Void div(int n1, int n2);

13
{
int result= n1/n2;
display(n1,n2,’/’,result);
}

Void rem(int n1, int n2);


{
if(n1>n2)
{
int result= n1-(n1/n2)*n2;
display(n1,n2,%,result);
}
Else
{
printf(“\t\t\t Please enter the first number bigger”);
}
}

 Output:-

Fig No.2.1 Output of calculator

Chapter No. 3
14
ALGORITHM & FLOWCHART

 Algorithm:-

Step 1:- Start


Step 2:- Declare function display, add, sub, mult, div, rem.
Step 3:- Declare n1,n2, ch in integer.
Step 4:- Declare c as a choice in char.
Step 5:- Read n1,n2,
Step 6:- do
Welcome to simple calculator.
Step 7:- Enter 1st Number.
Step 8:- Enter 2nd Number.
Step 9:- Menu of Calculator
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Remainder
Step 10:- Enter choice ch.
Step 11:- Read the choice.
Step 12:- Switch (ch)
Step 13:- case 1:-
add(n1, n2)
case 2:-
Sub(n1, n2)
case 3:-
Mult(n1, n2)
case 4:-
Div(n1, n2)
case 5:-
Rem(n1, n2)

default:
Please enter correct input.
Step 14:- Do you want to continue?(y/n)
If y then program will continue.
Else display message “Thanks for using Calculator.”
15
Step 15:- Stop.
Step 16:- Format of displaying output.
n1,ch,n2,result.
Step 17:- add(n1,n2)
Result= n1+n2
Step 18:- Sub(n1,n2)
Result= n1-n2
Step 19:- mult (n1,n2)
Result= n1*n2
Step 20:- div(n1,n2)
Result= n1/n2
Step 10:- rem(n1,n2)
Result=n1-(n1/n2)*n2

 Flowchart:-

16
17
18
CONCLUSION
It was a great experiences to design and implement the Human calculator by
using switch case and function using programming language c and to work on its
documentation. While working on this project .I have learned many things especially how to
apply concept in modelling of real world system. It also helpful me in getting in the better
understanding of basic programming concept of C language such as function, switch case.

19
REFERENCES

 https://codeforwin.org/2015/06/c-program-to-create-simple-calculator-using-switch-
case.html

 PCI Textbook

 https://aticleworld.com/calculator-in-c/

20

You might also like