0% found this document useful (0 votes)
70 views

Assignment On Programming

The document summarizes the development process of a program to sort numbers in ascending or descending order. It includes the algorithm, final code with explanations of functions used like printf and scanf. It also details the debugging process where mistakes in data types and functions were identified and corrected. Finally, it explains how debugging is used to develop programs by finding and fixing errors through checking variable values and outputs at different stages.

Uploaded by

Zakir Hossain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Assignment On Programming

The document summarizes the development process of a program to sort numbers in ascending or descending order. It includes the algorithm, final code with explanations of functions used like printf and scanf. It also details the debugging process where mistakes in data types and functions were identified and corrected. Finally, it explains how debugging is used to develop programs by finding and fixing errors through checking variable values and outputs at different stages.

Uploaded by

Zakir Hossain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Assignment on programming

Submitted to:
Ms Rukshana Aktar
Lecturer,
Department of IT
BAC International Study center
Submitted by:
Ibtesam Ahmed Adipto
ID- 2019141005
Department of IT
BAC International Study Center

pg. 1
Table of Contents
Final Code....................................................................................................................................................5
Debugging process......................................................................................................................................7
Explain the development process for the program...................................................................................10
how the debugging process can be used to develop a program?..............................................................11

pg. 2
Introduction-I am working as a Trainee Programmer in a software company named “Perl Soft”. I
have to write a program by using procedural programming language. The name of the program
will be “Number Sorting”.
Note: Sorting is a process of arranging items in some sequence from a list of items.
The program should have 2 options:
1. Ascending order
2. Descending order

After providing the option number (1 or 2) by user it will perform one of the operations,
otherwise it will give a message, “Wrong Option Number”.
For both option 1 & 2, user will provide the number of items (how many items user wants to
sort?). After providing number of items, user will provide the value of each item.
After the operations, program will simply show the sorted items in ascending order for option 1
and descending order for option 2 as result on the screen.

pg. 3
The Algorithm of the code is given below.
Binary to decimal:
Step 1> Input a decimal number n
Step 2> Initialize decimalNumber=0, i=0
Step 3> while (n != 0)
remainder = n%10
n /= 10
decimalNumber += remainder*pow(2,i)
++i
Step 4> Print decimalNumber

Decimal to binary:
Step 1> Input a binary number n
Step 2> Initialize binaryNumber=0, i=1
Step 3> while (n != 0)
remainder = n%2
n /= 2
binaryNumber += remainder*i
i *= 10
Step 4> Print binaryNumber

pg. 4
Final Code
In C program we can run both codes in one program by IF and ELSE, the code is below;

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

void main()
{
int choice=0;
printf("1 : Decimal to Binary. 2 : Binary to Decimal");
scanf("%d",&choice);
if(choice==1){
//Decimal to binary
int n,i=1,binaryNumber=0,remainder,a;
printf("Enter a decimal number");
scanf("%d",&n);
while(n!=0){
remainder=n%2;
n/=2;
binaryNumber+=remainder*i;
i*=10;
}
printf("%d",binaryNumber);
}
else{
//Binary to decimal
int n1,i1=0,decimalNumber1=0,remainder1,b1;
printf("Enter a binary number");
scanf("%d",&n1);
while(n1!=0){

pg. 5
remainder1=n1%10;
n1/=10;
decimalNumber1+=remainder1*pow(2,i1);
++i1;
}
printf("%d",decimalNumber1);
}
}

Result – After I have coded the output of this program is below


When we press 1, the option Enter a decimal number comes, and when we will press 2 the
option Enter a binary number comes

Figure-1

pg. 6
Figure-2

Debugging process
Debugging, in computer programming and engineering, is a multistep process that involves identifying a
problem, isolating the source of the problem, and then either correcting the problem or determining a
way to work around it. The final step of debugging is to test the correction or workaround and make
sure it works.
In this particular code I have made a lot of mistakes which will not run, the mistakes are, instead of int , I
wrote in, and instead of printf I wrote prinf.

Figure-3

pg. 7
Figure-4

After identifying the particular mistake, I have debugged the code

Figure-5

pg. 8
Now it will run smoothly , as I have debugged the code .

Figure-6

List of the codes I have used in this program


#include <stdio.h>

*The C programing language provides several commonplace library functions for file input and
output. These functions form up the majority of the C commonplace library header .
• the primary issue you may notice is that the first line of the file, the #include "stdio.h" line.
this can be noticeably just like the #define the preprocessor, except that rather than an easy
substitution, a complete file is scan in at this time.

#include<stdlib.h>
The stdlib.h header defines four variable sorts, many macros, and numerous functions for
activity general functions

Void main
This line gives the name of the function that we have written and information about what goes into and
out of the function. In this case, the name of the function is main.

pg. 9
Data types- int
An integer, in the context of computer programming, is a data type used to represent real numbers that
do not have fractional values. Different types of integer data types are stored on machines in different
ways.

Elseif

An if statement can be followed by an optional else statement, which executes when the
Boolean expression is false.

Scanf
n the C programming language, scanf is a function that reads formatted data from stdin (i.e, the
standard input stream, which is usually the keyboard, unless redirected) and then writes the results into
the arguments given.

Printf
Printf used to see that you typed or entered on your screen as an output

While loop
In most computer programming languages, a while loop is a control flow statement that allows code to
be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a
repeating if statement.

Explain the development process for the program


In this program first of all I have coded binary to decimal with the conditions of the algorithm,
then I have coded decimal to binary in the same way.
After that I have combined two codes in a single program, while combining the codes I have
used some programming language which helped me execute the program. There are, #include
<stdio.h>
#include <stdlib.h> stdio.h is the header file for standard input and output. This is useful for
getting the input from the user(Keyboard) and output result text to the monitor(screen).
Without this header file, one cannot display the results to the users on the screen or cannot
input the values through the keyboard

pg. 10
Then I have used void main, this line gives the name of the function that we have written and
information about what goes into and out of the function. In this case, the name of the function
is main.
And an integer because it is a whole number not a fraction with variables. Printf and scanf is
also used in this program for input and output results, and I have used while loop in this
program because the While Loop. The while loop is used to repeat a section of code an
unknown number of times until a specific condition is met. For example, say we want to know
how many times a given number can be divided by 2 before it is less than or equal to 1.
And finally I have used Else and IF to link both the codes to merge the program.

how the debugging process can be used to develop a program?


This is the first method or activity of a debugging process. For doing this with key attention the
output or the worth at every stage of the module or program should be checked. If any
discrepancy is found, then with bigger attention that sub portion should be checked to search
out the values passed to every variables and also the output that happens from each method
therein subdivision. One also can add some temporary statements or print or output
statements for checking the values of variables. These temporary statements should be
removed fastidiously when the debugging method. In some cases, it should be necessary to
recreate the bug to spot wherever it's occurred. therefore, the most plan of this step of
debugging method is to spot
What the bug or fault is – this will be done by recreation of bugs or by careful checking of
values
Where it's occurred – By writing temporary print or output statements or finding the place
wherever worth is modified or reasons why information isn't in correct format so on.
How it's caused so on.

Having done the most important method of debugging succeeding step in debugging is to mend
the error or bug.

Bug Fixing or Error Correction: this can be additionally concerned within the method of
debugging as a result of whereas we have a tendency to fix a blunder or bug there's risk that it's
going to offer raise to another bugs. If it happens once more the method mentioned higher
than particularly detection, correction takes place. This continues till the system is found to be
bug free.

pg. 11
Important Factors to contemplate whereas debugging

• whereas correcting or fixing a bug forever make it a habit to create comments containing
description regarding date, purpose of fixing, username UN agency fastened the bug so on. this
can be terribly essential as a result of this can be useful if the one who created the bug fixing
shortly wish to refer the bug for a few reason for fixing another fix or it'd be helpful for other
users since it act as a documentation that provides a straightforward reference.

• build it a apply that whereas debugging to create a modification and take a look at it
forthwith. this can be as a result of once a modification is formed to the prevailing code it's
going to pave method for a few a lot of bugs. when making certain that the corresponding fix
works fine by testing then choose next modification. In different words, it's essential to be
systematic in approach whereas debugging.

• it's terribly essential to get rid of the temporary code supplementary only for debugging
functions like temporary print statement to see the worth of variables so on.

• once a fault is found in debugging method when correcting and fixing it forever have a
broader vision and suppose whether or not identical fault or similar things will occur in different
components of the program. This vision can facilitate in reducing the time in debugging
method.

• whereas debugging it's forever sensible to follow the standard approach. Since by viewing
details in module level bigger details and bugs may be detected if any existing and additionally
correction of bugs becomes easier at the standard level and proceed intrinsically to completely
different modules then proceed to interfaces between modules.

Debuggers have several utilities and functions in it to call some are

pg. 12
Step-By-Step – It helps look the variables or worth of the program in every step and so
thorough analysis may be created simply.

Breakpoint – this can be used for pause the program at any time required. Say as an example if
a user needs to see the worth written in an exceedingly file once enter key's ironed then when
enter key is pressed if this breakpoint is employed then program is paused and also the user
may check the file.

The higher than mentioned is just some of the many talents or functions obtainable whereas
debugging exploitation debugging tools. no matter could the tool used it's necessary that one
ought to undoubtedly rectify their program or in different words it is important to follow the
debugging step in computer code development life cycle so as have a top quality product.

pg. 13
Reference
Debugging – An Important Aspect in Programming | IT Training and Consulting – Exforsys. 2019.
Debugging – An Important Aspect in Programming | IT Training and Consulting – Exforsys.
[ONLINE] Available at: http://www.exforsys.com/tutorials/programming-concepts/debugging-
a-important-aspect-in-programming.html. [Accessed 14 June 2019].
The Economic Times. 2019. Definition of Debugging | What is Debugging ? Debugging Meaning
- The Economic Times. [ONLINE] Available at:
https://economictimes.indiatimes.com/definition/debugging. [Accessed 14 June 2019].
Study.com. 2019. While Loop: Definition, Example & Results - Video & Lesson Transcript |
Study.com. [ONLINE] Available at: https://study.com/academy/lesson/while-loop-definition-
example-results.html. [Accessed 14 June 2019].

pg. 14

You might also like