You are on page 1of 17

BITS Pilani

K K Birla Goa Campus

CSF111
Computer Programming

Introduction
Teaching team

● Instructors ● Lectures: LT4


○ Swaroop Joshi (IC) ● Swaroop’s Office hours
○ Anup Mathew ○ WF 11:00-11:45 D-161
○ Arnab Paul ○ Or by appointment (calendly
● Lab instructors )
○ Swati Agarwal ○ Showing up without
○ Hemant Rathore appointment - not advised
○ Rizwan Parveen ● Anup's Office hours
● TAs ○ By appointment only.
○ No emails - only slack
● Arnab’s Office hours
○ TF 12:30-1:10PM D-253
Course handout ○ Appointments via Slack
Labs

● Four sections ● Open question, closed book


○ Wed 5:00-6:15 ○ Lab question will be
○ Wed 6:30-7:45 announced by Monday night
○ Thu 5:00-6:15 ○ You can seek help before
○ Thu 6:30-7:45 your lab starts
● Assigned by AUGSD ○ No discussion or referring
○ no change allowed any material during the lab
● Computer Center ● Auto-evaluated

No labs on: Mar 29-30, Apr 5-6, Apr 19-20, May 3-4. Last lab: Jun 28.
This course is about

● Fundamentals of Programming
● From specification to implementation
● Software engineering principles
● Developing viable notional machines

And not about


● A particular programming language
○ Although we use C as a tool to understand the concepts
● A particular software
○ Although we use VSCode and gcc for uniformity
● How program gets translated into electrical signals
Expectations from students

● Attend all lectures and labs


● Come prepared, especially for labs and quizzes
● Make use of Office Hours
● Make use of TAs’ time
● Maintain common-sense discipline for lectures and labs
● Behave like adults - be treated like adults
○ Responsible, Responsive, Respectful
What is a computer program?

Program = set of instructions for a computer to follow*

Input

Program

Output
Programming Languages

● Needed to write a program, i.e., to tell instructions to the computer


● What language does the computer understand?
○ 000101100110011…
○ Each machine has its own
■ programs not portable
○ Not easy for other humans to understand

Programming is a creative,
collaborative activity!
Programming Languages

● What’s better than machine language?


○ Assembly language: ADD R1 R2, …
○ Need a translator to convert this to machine instructions
○ Still machine dependent
○ Easier to read for humans
○ Difficult to form meaningful abstractions
■ e.g., “a tweet”, “a swipe motion”

A very important concept in


computing
Programming Languages

High-level languages
● C, C++, Java, Python, Haskell, Kotlin, Swift, …
○ hyp = sqrt(x*x + y*y)
● Do not rely on the underlying machine language
● Need a translator – a fairly complex software
● Much easier to read and understand for fellow humans
● Much easier to build meaningful abstractions
Translator (for our purposes, compiler)

Input

Program

Output
Translator (for our purposes, compiler)

Input

Program Compiler

Output
Our first program
Standard C libraries we need;
Details later

#include <stdio.h> A program is a set of instructions to follow


enclosed in the braces {…} under main; Details
later
int main() {
printf("My first program.");
return 0;
There are two instructions in this program
}
The first instruction, printf, takes a value and
tells the computer to print that value on the
screen

The second instruction, return 0, indicates we


exit this program successfully; Details later
Our first program

Input

#include <stdio.h>

int main() {
printf("My first program.");
return 0;
}
Output

What is the input to this program?


Not all programs have inputs

What is the output of this program?


Not all programs have outputs
Our first program - specify the behaviour

#include <stdio.h>

int main() {
printf("My first program.");
return 0;
} Displays My first program. on the
console
Our second program You can add as many printf instructions as you
want. They will be executed one after the
other in the given sequence.

#include <stdio.h>

int main() {
printf("My second program.");
printf("BITS"); “%d” is a special format specifier which acts
as a placeholder for an integer value
printf("goa");
printf("%d", 42);
return 0; What is the output of this program?
}

How do you know?


Reasoning about a program — Tracing
One of the most important skills for a programmer!

● Can you figure out what a given program does?


● We go line by line and answer the question: “what does this line do?”
Program Line What we see

printf("My second program.");

My second program.

printf("BITS");

My second program.BITS

printf("goa");

My second program.BITSgoa
Program Line What we see

printf("%d\n", 12+4);

16

printf("%d\n", 12+4*2);

16
20

printf("%d\n", 10/2+3);

16
20
8

printf("%d\n", 10/(2+3));

16
20
“\n” is a special sequence that tells printf 8
to print a new line 2

You might also like