0% found this document useful (0 votes)
8 views5 pages

Introduction to Computer Programming

The document provides an introduction to computer programming, covering fundamental concepts such as algorithms, programming languages, and types of errors. It discusses the evolution of C++, its object-oriented features, and programming methodologies, including procedural and object-oriented programming. Additionally, it includes syntax basics, data types, functions, and examples of conditional statements and error handling in C++.

Uploaded by

liesacarlum
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)
8 views5 pages

Introduction to Computer Programming

The document provides an introduction to computer programming, covering fundamental concepts such as algorithms, programming languages, and types of errors. It discusses the evolution of C++, its object-oriented features, and programming methodologies, including procedural and object-oriented programming. Additionally, it includes syntax basics, data types, functions, and examples of conditional statements and error handling in C++.

Uploaded by

liesacarlum
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

Computer Programming Algorithm - Step-by-step solution to a

problem.
Week 1 Introduction to Computer
Programing Problem-solving steps
1.​ Problem Analysis - recognizing the
problem
Computer Program
2.​ Algorithm Design - step-by-step
●​ The way computer works.
solution
3.​ Coding
What is Programming?
4.​ Execution
●​ Plan to execute a program.
●​ Sequence of statements intended to
Pseudocode - blueprint for translating the
accomplish a task.
code's logic into an actual programming
●​ Set of instructions for a computer to
language.
follow.
-​ Arithmetic operations (+, -, *, /)
●​ Brainstorming
-​ Assignment (=)
-​ Comparison (=, ≠, , ≤, ≥)
Programming Language - use to
-​ Logical (and, or)
communicate with computers
-​ Certain keywords can be used as a
●​ Low-level language - provides
command, such as PRINT, WRITE,
minimal abstraction from hardware
READ, SET, GO TO, etc.
○​ Machine Language - binary
-​ Indentation is used to indicate
codes (0,1)
branches and loops of instructions.
○​ Assembly Language -
humanoid language
Flowcharts - represent algorithms visually
●​ High-level language - capable to
understand natural language
○​ Syntax - step-by-step
process
○​ Commands - instruct the
computer
○​ Compiler - translate entire
program before execution
○​ Interpreter - line based

Types of Errors
●​ Syntax Error - commands are
misspelled or rules are broken.
-​ wrong code-no output
●​ Logical Error - syntax/code is
correct but output is wrong.
●​ Debugging - Process of finding and
fixing errors
Programming Methodology - approach to
solve problem Week 2 Introduction to C++
●​ Procedural Programming - Breaks
problem into smaller functions History of C++
-​ Best for small, simple
programs ●​ Developed by Bjarne Stroustrup in
-​ one label at once 1979 at Bell Labs
●​ Originally called 'C with Classes'.
○​ Csharp
●​ Added Object-Oriented features to
C.
●​ released in 1985.

Object-Oriented Programming

●​ paradigm based on objects.


●​ Objects combine data (attributes)
and behavior (methods).
●​ Object-Oriented Programming - ●​ Supports concepts like
Organizes around objects and data encapsulation, inheritance, and
-​ Suitable for complex polymorphism.
problems
-​ Check connection and C++
similarities ●​ High performance with low-level
control.
●​ Rich standard library and third-party
libraries.
●​ Procedural and object-oriented
programming.
●​ Big Systems, games, and
applications.
●​ objects>function
Set-up
●​ Compiler translates code (e.g.,
GCC, Clang, MSVC).
●​ IDE (e.g., Code::Blocks, Visual
Studio, VS Code) for development.
●​ Typical process: Write → Compile
→ Link → Execute.

First Program: Hello, World!

#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}

Syntax Basics
Fixed-size types = variations of int that give
you smaller or bigger number ranges.
●​ Statements end with a semicolon (;).
●​ short → Usually 2 bytes (−32,768 to
●​ Code blocks enclosed in curly
32,767).
braces { }.
○​ Example: short s = 100;
●​ Comments: // single-line, /* multi-line
●​ long → Usually 4 bytes on 32-bit
*/.
systems, 8 bytes on 64-bit (platform
●​ Operators: +, -, *, /, %, ++, –.
dependent).
○​ Example: long population =
Data Types
1000000;
●​ long long → Always at least 8
1.​ int - store whole numbers
bytes, allows very large integers (−9
2.​ float - store 6-7 decimal places
quintillion to +9 quintillion).
(single procedure)
○​ Example: long long bigNum
3.​ double - 7-16 decimal places
= 1234567890123;Casting:
(double procedure)
(int)3.14 → 3,
4.​ char - store single characters or
static_cast<int>(3.14).
small integer (1byte)
-​ ‘’
Functions in C++
5.​ string - store 2 characters
●​ Functions group reusable code.
-​ “”
●​ Syntax: returnType
6.​ bool - true or false
functionName(parameters) { ... }
7.​ // - single line comment
●​ Pass by value vs pass by reference.
8.​ /* */ - multiple line comment
●​ Can return values or void.
Errors and Debugging EXAMPLE!!
●​ Syntax Errors - Violation of
grammar [Link] a single code that ask for grade and
○​ (e.g., missing semicolon). identify if the given output is a passing
●​ Logic Errors - Program runs but grade.
produces wrong result.
●​ Run-time Errors - Occur during #include <iostream>
execution using namespace std;
○​ (e.g., division by zero). int main(){
●​ Use debugger to step through code int grade;
and inspect variables. cout<<”what is your grade?” <<endl;
cin>>grade;
Classes and Encapsulation if(grade>=75){
●​ Class - Blueprint for objects. cout<<”You Passed”;
●​ Encapsulation: Hiding data, }
exposing behavior via methods. else{
●​ Access specifiers: public, private, cout<<”You Failed”;
protected. }
●​ Example: class Rectangle { int width,
height; public: int area(); };
2.
class Rectangle { #include <iostream>
int width, height; using namespace std;
public: int main(){
Rectangle(int w, int h) { width=w; int age = 18;
height=h;} if(age =18){
int area() { return width * height; }}; cout<<”You can now vote”
}
else if(age<=16){
WEEK 3: Conditional Statements cout<<”You are not qualified to
vote”;
Conditional Statements }
●​ if – execute a code to identify if the else{
condition is true cout<<”Wait for another year”;
●​ else – provide an alternative block to }
code if the condition is false
●​ else if- specify a new condition to 3. currency calc
test, if the first condition is false.
#include <iostream>
using namespace std;

int main() {
double peso;
double usd = 0.017174;
double euro = 0.0148325;
double pound = 0.012930; cout<<"Enter Operators:";
double yen = 2.608307; cin>> op;
string currency; if([Link]()){
cout<<"Invalid Input!" <<endl;
cout<< "Peso currency calculator" <<endl; }
cout<< "Enter number in peso.";
cin>> peso; cout<<"Enter 2nd Number:";
if(peso > 0) { cin>>num2;
cout<< "Choose currency to be if([Link]()){
converted to. (usd, euro, pound, yen)";} cout<<"Invalid Input!" <<endl;
else if(peso<0) { }
cout<< "Error"; else if(op=='+'){
} cout<<"Result:" <<num1+num2;
cin>> currency; }
if (currency=="usd") { else if(op=='-'){
cout<< "Result:" << peso*usd; cout<<"Result:" <<num1-num2;
} }
else if (currency=="euro") { else if(op=='*'){
cout<< "Result:" << peso*euro; cout<<"Result:" <<num1*num2;
} }
else if (currency=="pound") { else if(op=='/'){
cout<< "Result:" <<peso*pound; cout<<"Result:" <<num1/num2;
} }
else if (currency=="yen") { else{
cout<< "Result:" << peso*yen; cout<<"Invalid Opperator";
} }
else { return 0;
cout<<"Invalid input!"; }
}
}

[Link]
#include <iostream>
using namespace std;
int main (){
double num1, num2;
char op;

cout<<"Enter 1st Number:";


cin>> num1;
if([Link]()){
cout<<"Invalid Input!" <<endl;
}

You might also like