0% found this document useful (0 votes)
6 views26 pages

Lecture1 C#

Uploaded by

levisqueen26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views26 pages

Lecture1 C#

Uploaded by

levisqueen26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

The United African University of Tanzania

CS111 Procedural Programming in C


BCEITI

CS111
Course Introduction
Course Code: CS111
Course Name: Procedural Programming in C
Lecturer: Mr. Gambadu
E-mail: [email protected]
Mobile: +255 762 457 578
Office: CoET Lecturers Room

CS111
Course Introduction
Course aim:
This course is designed for students with no prior programming experience. It covers
the fundamental concepts of design, development, testing, and debugging
intermediate-level programs in a procedural language such as C.

CS111
Course Introduction
Learning Outcomes: At the end of the course, student should be able to:
• Demonstrate the ability to explain the nature of procedural programming and the
process of converting source code to an executable.
• Demonstrate the ability to write sequential code by developing applications that
implement algebraic type equations.
• Demonstrate the ability to use control structures such as if statement, switch
statement, for loop, while loop and others by developing applications that uses
these statements and nested control statements.
• Demonstrate the ability to use arrays, strings, and structures.
• Demonstrate the ability to use pointers by developing applications that incorporate
pointers to access and manipulate both simple and complex data types.
• Demonstrate the ability to use files by developing applications that reads and writes
data to and from a sequential file.
CS111
Course Contents

CS111
Course Contents

CS111
Course Introduction
• Course status: Core
• Credit rating: 12 Credits
• Total hours spent: 120 hours
• Pre-requisite: None
• Teaching and learning activities
• Lectures, Tutorials, Lab Sessions
• Assessment methods
• Coursework Assessment (Tests + Assignments + Quiz): 40%.
• Final Exam: 60%.

CS111
• Class Time:
• Fridays: 0830 – 1130
• Venue: LRM 104/Computer Lab
• Reading List
• C How to Program, Global Edition. Pearson Education UK. Deitel, Paul, and Harvey
Deitel, 2015. ISBN-13: 978-0133976892.
• C programming: a modern approach. WW Norton & Company. King, Kim N, 2008.
ISBN-13: 978-0393979503.

CS111
• Class norms
• Mobile phones – silent mode
• Punctuality
• Attendance (75% minimum)
• Medium of communication – English
• Do not have private conversations
• Respect other colleagues’ opinions
• Consultation hours
• Wednesdays: 1300 – 1500 (Call or e-mail first for convenience)

CS111
Unit 1: Introduction to programming
• Programming and Programming Languages
• Programming process: Define the problem, Design Solution, Code, Test, Document.
• Processing a high-level program.

CS111
Computer Programming
• Computer programming or just programming is the process of creating a set of
instructions that tell a computer how to perform a task.
• The term programming means to create (or develop) software, which is also called a
program.
• In basic terms, software contains the instructions that tell a computer—or a
computerized device—what to do (e.g. find total sales, authenticate user etc.)
• Software developers create software with the help of powerful tools called
programming languages.
• Each language has strengths and weaknesses.

CS111
Programming Languages …
• A programming language - a language that a computer can understand (not human
languages).
Type of Programming Languages:
• Machine Language
• A set of built-in primitive instructions that are given in the form of binary code (0’s
and 1’s).
• Example: To add two numbers you can write the following instruction:
1101101010011010
• Assembly Language
• An alternative to machine language due to the difficulties in programming using
machine language.

CS111
Programming Languages …
• Assembly language uses short descriptive words (mnemonic) to represent the
machine-language instructions. For example: add – for adding numbers; sub – for
subtracting numbers etc.
Example: add 1, 1, result.
• Assembly language is a low-level language, close in nature to machine language. It
is machine-dependent.
• An assembler—is used to translate assembly-language programs into machine code.

CS111
Programming Languages …

CS111
Programming Languages ….
High-Level Language
• High-level languages are platform or machine independent, i.e. you can run them in
different types of machines.
• The instructions in a high-level programming language are called statements.
Example: area = 4 * 4 * PI;

CS111
Programming Process
• Developing a program requires roughly the following steps:
Step 1: Define the problem:
• Understand what the program is supposed to do.
• Identify INPUT and OUTPUT.
• INPUT: Data the user gives the computer before processing.
• OUTPUT: Information the computer gives the user after processing.
Step 2: Plan/Design the solution
• Find out how to solve the problem step by step.
• Here we write algorithms.
• Two common ways of planning the solution to a problem are to draw a flowchart
and/or write pseudocode.
CS111
Programming Process
• Flowchart is a pictorial representation of an ordered, step-by-step solution to a
problem.
• Pseudocode is an English-like language that lets you state your solution with more
precision than you can in plain English but less precision than is required when
using a formal programming language.
• More on Flowchart and Pseudocode later.
• Note: The above two steps tell you that you must know what you want the
machine to do.
Step 3: Code the program
• The programmer translates the logic from the algorithm (flowchart or pseudocode)
to a high-level programming language.

CS111
Programming Process
• There are many programming languages such as BASIC, COBOL, Pascal, FORTRAN, C,
C++, JAVA etc.
• To get the program to work, programmers have to follow exactly the rules -
the syntax - of the language they are using.
Step 4: Test the program
• Test to see if it is right problem, right answer, and right syntax.
• There are two kinds of errors: syntax error and logic error.
• A syntax error is any violation of the rules of the programming language, such
as using a period instead of a semicolon. Compiler will give an error message.
• E.g. Printf(“Hello world!”).
• Errors: “Printf” instead of “printf” and “.” Instead of “;”

CS111
Programming Process
• A logic error occurs when the computer does what you tell it to do but is not doing
what you meant it to do or the program can only fit for some data but not all.
• It is an error in thinking on the part of the program.
• Compiler will NOT give error message.
• You may get an output but the output is not the solution of your problem.
Example of logic error:
• The following example (written in C language) should divide two numbers each
other instead of finding half of the sum of two numbers.

CS111
Programming Process
Example of logic error:
• Let number be equal to the number of erasers bought.
• Let total be the total amount of money paid for all erasers
• Let average be equal to the average price for erasers.
• If in your program you calculate average using the formula:
average = (total + number) / 2;
instead of
average = total / number;
• Then this will result into logic error.

CS111
Programming Process
Full program written in C language:
#include <stdio.h>
int main(void){
double total, average;
int number;
printf("How many erasers did you buy? \n");
scanf("%d",&number);
printf("How much did you pay? \n");
scanf("%lf", &total);
average = (total + number)/2; //should be average = total/number
printf("Average price for each is: %g", average);
return 0;
}
CS111
Programming Process
• Debug - Search for and fix any errors in the program.
Step 5: Document the program
• Write the comments (explanations )of the program for yourself or someone else to
understand the codes of program.

CS111
Processing a High-Level Language Program
• A program written in a high level language such as C, C++, Java etc is called a source
program or source code.
• Use a text editor to create the source code.
• To verify that your source code is syntactically correct, you must use a compiler to
translate your source code into its equivalent machine language program which is
called the object program or object code.
• Next, you must use a program called a linker to combine your object code with
any prewritten code (programs) used from available libraries (e.g. the math library
contains code for frequently used mathematical functions) to create executable
code, code the computer can execute.
• A program called a loader is now used to load the executable code into main
memory so that the program can be executed.
• Last but not least, you must execute your program.
CS111
Processing a High-Level Language Program…
• Compile -- translate source code into machine language
• Link -- combine with other programs that are needed
• Load -- load into the computer's memory
• Run -- execute the program

CS111
Processing a High-Level Language Program
Steps

CS111
Processing a High-Level Language Program…
• high-level language - computer languages such as Java,Basic, Pascal, FORTRAN,
COBOL, C or C++ that are closer to natural languages like Swahili, English, French,
German or Spanish
• source code or program - a program written in a high-level language
• object code or program - the machine language version of the source code.
• library - prewritten code (program)
• linker - a program that combines the object code with other programs or code
located in a library, and used in the program to create the executable code or
program
• loader - a program that loads the executable code into main memory
• In this class we will learn about C Programming Language.

CS111

You might also like