CS101x S05 Dumbo Computations IIT Bombay

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

IIT Bombay

Computer Programming
Dr. Deepak B Phatak
Dr. Supratik Chakraborty
Department of Computer Science and Engineering
IIT Bombay

Session: Dumbos computations

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay 1


Recap
IIT Bombay

We got introduced to Mr Buddhuram Dumbo,


has tools to perform input, output and assignment
We also defined how to write a program for Mr. Dumbo
Instructions for Input, Output, Assignment
A declaration, to announce names used in a program

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay 2


Overview of This Lecture
IIT Bombay

We will see how Dumbo executes a program


Possible problems in handling input/output
And a solution
Moving over to C++

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay 3


A Computational problem
IIT Bombay

Given the number of boys and girls in a class, find the total
number of students in the class

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay 4


Program Design
IIT Bombay

We need to read two input values


Let us use names NBOYS and NGIRLS for these values
We need to calculate one result
Let us use the name NSTUDENTS to represent the result
We figure that the value to be assigned to NSTUDENTS is the
sum of the two numbers NBOYS and NGIRLS

The program can now easily be written

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay 5


A Program for Mr. Dumbo
IIT Bombay

Input NBOYS;
Input NGIRLS;
NSTUDENTS = NBOYS + NGIRLS;
Output NSTUDENTS;

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay 6


The Correct Program for Mr. Dumbo
IIT Bombay

Use locations NBOYS, NGIRLS, NSTUDENTS;


Input NBOYS;
Input NGIRLS;
NSTUDENTS = NBOYS + NGIRLS;
Output NSTUDENTS;

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay 7


Dumbo in action
IIT Bombay

Watch Mr. Dumbo execute our program

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay 8


Summary
IIT Bombay

Using Mr. Dumbo, we have understood basic operations that


a computer can carry out
Possible major components of a computer
Memory, I/O, Registers for computations
We have seen how Dumbo executes a program

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay 9

You might also like