0% found this document useful (0 votes)
24 views40 pages

Lecture 1

Uploaded by

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

Lecture 1

Uploaded by

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

Department of Computer Science & Engineering

UNIVERSITY OF MINES AND TECHNOLOGY

COMPUTER PROGRAMMING

BY: DR MILLICENT AGANGIBA


Presentation Outline
Introduction to programming
Data types
Variables

Declaration of variables

Assignment

Operators
COURSE DESIGN
۞ Course Code: GL/MN-351
۞Credits: (2,1,2)
۞Prerequisites: Computer Programming
۞References
◦Title: C# Programming From Problem Analysis to
Program Design, 5th Edition or 3rd Edition.
◦Author: Barbara Doyle
◦Publisher: Cengage, 1088 pp, 2016 or 832pp, 2010
COURSE OUTLINE
۞Elements of programming.
۞Data description statements.
۞Control structures.
۞Data types.
۞Data-processing statements.
۞Input and output (I/O) statements.
COURSE OUTLINE
۞Procedure for writing algorithms
۞Building application.
۞Steps in developing application.
۞Decisions.
۞Conditions and loops.
۞Arithmetic operators.
۞Programming applications in Engineering.
EVALUATION METHODS
۞Assignments
۞Labs
۞Quizzes
۞Final Exam
INTRODUCTION
۞A "programming language" is a medium
designed to allow humans to give instructions or
describe consecutive actions to be executed by a
computer.
۞The language used by the processor is called
machine code.
۞The code that reaches the processor consists
of a series of 0s and 1s known as binary data.
INTRODUCTION
۞Machine code is therefore difficult for humans
to understand
۞Hence, the need for intermediary languages,
which can be understood by humans.
۞The code written in this type of language is
translated into machine code using compilers and
interpreter for the computer to process.
INTRODUCTION
There are several basis for classifying programming
languages:
۞Based on Levels of Abstraction
۞Based on How codes are Translated to
Machine Code
۞Based on Programming Paradigm.
INTRODUCTION
Classification Based on:
Based on Levels of Abstractions
۞Low Level Languages
۞High Level Languages
CATEGORIES
TWO CLASSES OF PROGRAMMING
LANGUAGES:
Low Level Languages High Level Languages

• Designed to program the computer at • High level of abstraction i.e Closer to


very low-level of abstraction; i.e. Machine human understanding;
Level
•Needs translation by compiler or
•Little or no abstraction i.e Closer to interpreter
Machine understanding;
• Machine Independent languages
• Difficult for humans. Eg. C++, VB, C#.

• Machine dependent languages

Eg. Machine Language,


Assembly Language.
INTRODUCTION
Classification Based on:
How codes are Translated to Machine Code:
۞Compiled languages
۞Interpreted languages
۞Intermediary language
TRANSLATION
COMPILED, INTERPRETED, OR
INTERMEDIARY LANGUAGE?
Main application Compiled/interpret
Language
area ed

ADA Real-time Compiled

BASIC Educational purposes Interpreted

C System programming Compiled

System object
C++ Compiled
programming
TRANSLATION
COMPILED, INTERPRETED, OR INTERMEDIARY
LANGUAGE?
Language Main application area Compiled/interpreted

Cobol Management Compiled

Fortran Calculation Compiled

Internet oriented
Java Intermediary
programming

MATLAB Mathematical calculations Interpreted language


Classification
Classification Based on:
Based on Programming Paradigm:
۞Object- oriented
۞Imperative or procedural
۞Concurrent
۞Functional
۞Scripting
In this course, we would practice Computer
Programming using C#.
FEATURES OF C#
I. Simple.
II. Modern programming language.
III. Object oriented.
IV. Type safe.
V. Interoperability.
VI. Scalable and Updateable.
VII. Component oriented.
VIII.Structured programming language.
STRUCTURE OF C#
Basic C# program consists of the following
things.
✓Namespace declaration
✓A Class
✓The Main method
✓Statements and Expressions
✓Comment
EXAMPLE OF C# PROGRAM
using System;
namespace HelloWorldApplication Namespace
{
class HelloWorld Class
{
static void Main(string[] args) Main method
{
/* my first program in C# */ Comment
Console.WriteLine("Hello World"); Statement
}
}
}
IMPORTANT THINGS TO NOTE (C#)
۞C# is case sensitive.
۞C# program execution starts at the Main
method.
۞All C# expression and statements must
end with a semicolon (;).
۞ File name is different from the class
name.
Data Types
Data Types
۞The type of data that a variable declaration
specifies and defines what type of information will be
stored in the allocated memory space.
۞Each time a variable is declared, C# requires that
the variable data type is specified. This is because
C# is a strongly typed language. Therefore prior to
using a variable, the compiler must be aware of
it….aware of what type of data is expected.
Data Types
Data types

In the C# programming language,


data types are divided in three
categories:
❑value types
❑reference types
❑pointer types
Data types
Data Variables

۞are memory/storage locations that hold data that


can be changed during project execution.
۞Every variable has a type that determines what
values can be stored in the variable
۞Used in programming for storing values, calculating
and for reusability.
Constants

۞Memory locations that hold data that cannot be


changed during project execution
۞declared using the keyword CONST and are given a
name, a data type, and a value
۞Syntax
const type identifier = expression;
Declaring a Variable

۞When you declare a variable or a named constant,


the compiler reserves an area of memory and assigns
it a name, called an identifier.
۞Identifier names are specified according to the rules
of recommended naming conventions.
۞The syntax of declaring a variable is as follows:
DataType VariableName;
Declaring a Variable
۞Identifier
۞Name
Rules for creating an identifier
✓Combination of alphabetic characters (a-z and A-Z), numeric digits (0-
9), and the underscore
✓First character in the name may not be numeric
✓No embedded spaces – concatenate (append) words together
✓Keywords cannot be used
✓Use the case of the character to your advantage
✓Be descriptive with meaningful names
✓Follow naming conventions / general naming conventions
Declaring a Variable
int studentCount; // number of students in
the class
int numberOfExams; // number of exams
int coursesEnrolled; // number of courses
enrolled
Assignment
To store a value in a variable you must use an
=. Here is an example of how to store the
value 5 inside an integer variable.

MyInt = 5;

You can store a value inside a variable


when you declare it. This is called
initializing the variable.

int MyInt = 5;
C# - Operators
An operator is a symbol that tells the compiler to
perform specific mathematical or logical manipulations.
C# has rich set of built-in operators and provides the
following type of operators:
➢Arithmetic Operators
➢Relational Operators
➢Logical Operators
➢Assignment Operators
Arithmetic Operations
Arithmetic Operations
۞Following table shows all the arithmetic operators supported by C#. Assume
variable A holds 10 and variable B holds 20 then An operator is a symbol that tells
the compiler to perform specific mathematical or logical manipulations.
Arithmetic Operations
Mathematical Functions: The common mathematical
functions in C# include:
Basic Arithmetic Operations

int num = 100;


messagebox.show (num++); // Displays 100
messagebox.show(num); // Display 101
messagebox.show(++num); // Displays 102
Relational Operators
Following table shows all the relational operators supported by C#.
Assume variable A holds 10 and variable B holds 20, then −
Logical Operators
Following table shows all the logical operators supported by C#. Assume
variable A holds Boolean value true and variable B holds Boolean value false,
then −
Assignment Operators
There are following assignment operators supported by C# −

You might also like