Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
162 views

Programming Module

Uploaded by

Mark San Andres
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
162 views

Programming Module

Uploaded by

Mark San Andres
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 103

Everyone makes

University
University
it Nueva
of of
in Caceres
Nueva Caceres
aCollege
nurturing
College of
ofEngineering
Engineering andand
Architecture
Architecture
environment.

ENGINEERING & ARCHITECTURE

By: James Francis B. Aguilar

We champion
excellence
______________________________________
We nurture Dreams Name of Student

We do the right
things right
______________________________________
We are dynamic Instructor
and creative

We respect each other


and work as a team

cea@unc.edu.ph
054-4726100 loc. 121
COPYRIGHT © 2020
UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

CONTENTS
CONTENTS ............................................................................................................................................................. 2
COURSE DETAILS(TO EDIT) ..................................................................................................................................... 5
WEEK 1: INTRODUCTION TO COMPUTER FUNDAMENTALS .................................................................................... 6
INTRODUCTION ......................................................................................................................................................6
COMPUTER OVERVIEW ............................................................................................................................................7
HISTORY OF THE COMPUTER .....................................................................................................................................8
LABORATORY ACTIVITY NO. 1 .................................................................................................................................13
WEEK 2: HARDWARE AND SOFTWARE ................................................................................................................. 16
INTRODUCTION ....................................................................................................................................................16
HARDWARE & SOFTWARE .....................................................................................................................................16
EVOLUTION OF OPERATING SYSTEM.........................................................................................................................21
PROGRAMMING SOFTWARE AND UPDATES ...............................................................................................................22
LABORATORY ACTIVITY NO.2 .................................................................................................................................25
WEEK 3: CLASSIFICATION OF SOFTWARE ............................................................................................................. 28
INTRODUCTION ....................................................................................................................................................28
CLASSIFICATION OF SOFTWARE ...............................................................................................................................28
LABORATORY ACTIVITY NO. 3 .................................................................................................................................30
WEEK 4: THE NUMBER SYSTEM............................................................................................................................ 33
INTRODUCTION ....................................................................................................................................................33
NUMBER SYSTEM .................................................................................................................................................33
NUMBER SYSTEM TABLE OF CONVERSION .................................................................................................................33
CONVERSION PROCEDURE......................................................................................................................................34
LABORATORY ACTIVITY NO. 4 .................................................................................................................................40
WEEK 5: INTRODUCTION TO PROGRAMMING ..................................................................................................... 43
INTRODUCTION ....................................................................................................................................................43
THE C COMPILER .................................................................................................................................................43
WEEK 6: PRINTING A LINE OF A TEXT ................................................................................................................... 47
INTRODUCTION ....................................................................................................................................................47
A SIMPLE C PROGRAM: PRINTING A LINE OF A TEXT ....................................................................................................47
LABORATORY ACTIVITY NO. 6 .................................................................................................................................49
WEEK 7: MEMORY CONCEPT ................................................................................................................................ 53
INTRODUCTION ....................................................................................................................................................53
MEMORY CONCEPT (UNDERSTANDING VARIABLES) .......................................................................................53
COMMON PROGRAMMING ERROR .................................................................................................................53
RULES OF OPERATOR PRECEDENCE .................................................................................................................53
LABORATORY ACTVITIY NO. 7 .................................................................................................................................54
WEEK 8: USING IF AND IF.. ELSE STATEMENT ...................................................................................................... 57
INTRODUCTION ....................................................................................................................................................57

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 2


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

DISCUSSION ........................................................................................................................................................57
LABORATORY ACTIVITY NO. 8 .................................................................................................................................59
WEEK 9: FORMULATING ALGORITHM .................................................................................................................. 62
INTRODUCTION ....................................................................................................................................................62
DISCUSSIONS.......................................................................................................................................................62
LABORATORY ACTVITY NO. 9..................................................................................................................................64
WEEK 10: THE GENERAL FORMAT OF THE FOR AND WHILE STATEMENT ............................................................. 70
INTRODUCTION ....................................................................................................................................................70
GENERAL FORMAT ...............................................................................................................................................70
EXAMPLES ..........................................................................................................................................................70
WEEK 11: UNDERSTANDING ALGORITHM ............................................................................................................ 72
INTRODUCTION ....................................................................................................................................................72
OBJECTIVES .........................................................................................................................................................72
USING FOR LOOP ..................................................................................................................................................72
LABORATORY ACTIVITY NO. 11 ...............................................................................................................................74
WEEK 12: FORMULATING ALGORITHM CASE STUDY ............................................................................................ 78
INTRODUCTION ....................................................................................................................................................78
ALGORITHM DIFFERENT CASES ...............................................................................................................................78
ASSIGNMENT OPERATORS ..............................................................................................................................78
PREINCREMENTING VS. POSTINCREMENTING ................................................................................................79
PSEUDOCODE ..................................................................................................................................................79
FLOW CHART ...................................................................................................................................................79
EXAMPLE (PROBLEM SOLVING) .......................................................................................................................80
WEEK 13: BREAK AND CONTINUE ........................................................................................................................ 81
INTRODUCTION ....................................................................................................................................................81
OBJECTIVES .........................................................................................................................................................81
BREAK AND CONTINUE STATEMENTS .............................................................................................................81
LABORATORY ACTIVITY NO. 13 ...............................................................................................................................83
WEEK 14: SWITCH MULTIPLE SELECTIONS ............................................................................................................ 85
INTRODUCTION ....................................................................................................................................................85
OBJECTIVES .........................................................................................................................................................85
DO WHILE REPETITION STATEMENT ................................................................................................................85
SWITCH MULTIPLE-SELECTION STATEMENT ...................................................................................................86
LABORATORY ACTIVITY NO. 14 ...............................................................................................................................88
WEEK 15: FUNCTIONS .......................................................................................................................................... 91
INTRODUCTION ....................................................................................................................................................91
C STANDARD LIBRARY ...........................................................................................................................................91
PROGRAMMER-DEFINED FUNCTIONS ........................................................................................................................91
MATH LIBRARY FUNCTIONS ....................................................................................................................................91
THE MATH LIBRARY FUNCTIONS .....................................................................................................................92
WEEK 16: MATH LIBRARY FUNCTIONS ................................................................................................................. 93

3 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

INTRODUCTION: ...................................................................................................................................................93
OBJECTIVES .........................................................................................................................................................93
EXAMPLE ............................................................................................................................................................93
LABORATORY ACTIVITY NO. 16 ...............................................................................................................................94
WEEK 17: RANDOM NUMBER GENERATIONS ...................................................................................................... 96
INTRODUCTION ....................................................................................................................................................96
OBJECTIVES .........................................................................................................................................................96
RAND FUNCTION ..................................................................................................................................................96
LABORATORY ACTIVITY NO. 17 ...............................................................................................................................98
WEEK 18: APPLICATION OF C IN SOLVING ENGINEERING FORMULAS ................................................................ 101
INTRODUCTION ..................................................................................................................................................101
OBJECTIVES .......................................................................................................................................................101
LABORATORY ACTIVITY NO. 18 .............................................................................................................................102
REFERENCES....................................................................................................................................................... 103

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 4


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Course Details
Course Code : Comp224g/ CE214g/ …
Course Title : Computer Fundamentals and Programming
Units : 2 units lab
Commitment : 6 hrs per week
Course Description : This hands-on course provides a comprehensive introduction to computer
fundamentals and programming. In the beginning students learn the
fundamentals of computers. Afterwards, students will learn the computer
programming process. They’ll work on projects reflecting industry work
scenarios. Students also learn how to program using other important
programming languages and are introduced to various software tools that aid
in the many facets of the software development process.
Prerequisites : None
Textbook :
References : D. &. A. I. Paul Deitel, "C How to Program," in C How to Program, 10th Edition, 2017.

Couse Outcomes : After completion of the course the student should be able to:
1. Familiarize with the computer fundamentals
2. Use Compiler to write a C program
3. Analyze flow chart and create C program equivalent
4. Create a engineering program application
Resources Required : Workbook, PC with Good internet connections,
Software Required : Online C Compiler, C Free V5.0 or higher
Quizzes : None
Examination : Midterm and Final Examination in the form of exam and programming

Midterm Finals
Assessments Percentage Assessments Percentage
Major Exams 50% Major Exams 50%
Laboratory Exercises 40% Laboratory Exercises 40%
Attendance 10% Attendance 10%

Total 100% Total 100%


General Average 40% Midterm Ave + 60% Final Ave.
Required Gen Ave. to Pass 75%

5 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 1: Introduction to Computer Fundamentals

Introduction

[1]A computer is a programmable device that stores, retrieves, and processes information. ... The
term was later given to a mechanical device as they began replacing the human computers.
Today's computers are electronic devices that accept data (input), process that data, produce output, and
store (storage) the results.

A computer is a apparatus that can be instructed to carry out sequences of arithmetic or logical
operations automatically via computer programming. Modern computers have the ability to follow
generalized sets of operations, called programs. These programs enable computers to perform an
extremely wide range of tasks. A "complete" computer including the hardware, the operating system
(main software), and peripheral equipment required and used for "full" operation can be referred to as a
computer system. This term may as well be used for a group of computers that are connected and work
together, in particular a computer network or computer group.

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 6


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Computer overview

[1] Below is a picture of a computer with each of the main components. In the image below, you can see
the desktop computer, flat-panel display, speakers, keyboard, and mouse. We've also labeled each of the
input devices and output devices.

Figure 1.1 [1]

7 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

History of the computer

[1]The first digital computer and what most people think of as a computer was called the ENIAC. It was
built during World War II (1943-1946) and was designed to help automate the calculations being
completed by human computers. By doing these calculations on a computer, they could achieve results
much faster and with less errors.

Early computers like the ENIAC used vacuum tubes and were large (sometimes room size) and only found
in businesses, universities, or governments. Later, computers began utilizing transistors as well as smaller
and cheaper parts that allowed the ordinary person to own a computer.

When was the word "computer" was first used?


The word "computer" was first used in 1613 in the book The Yong Mans Gleanings by Richard
Braithwaite and originally described a human who performed calculations or computations. The
definition of a computer remained the same until the end of the 19th century, when the industrial
revolution gave rise to machines who calculations or computations. The definition of a computer
remained the same until the end of the 19th century, when the manufacturing revolution gave rise to
machines whose primary purpose was calculating.

First mechanical computer or automatic computing engine concept

In 1822, Charles Babbage conceptualized and began emerging the Difference Engine, considered
to be the first automatic computing machine. The Difference Engine was capable of computing several
sets of numbers and making hard copies of the results. Babbage received some help with
development of the Difference Engine from Ada Lovelace, considered by many to be the first
computer programmer for her work on the Difference Engine. Unfortunately, because of funding,
Babbage was never able to complete a full-scale functional version of this machine. In June 1991, the
London Science Museum completed the Difference Engine No 2 for the bicentennial year of Babbage's
birth and later completed the printing mechanism in 2000.

Figure 1.2 [1] In 1837, Charles Babbage proposed the first


general mechanical computer, the Analytical Engine. The
Analytical Engine contained an ALU (Arithmetic Logic Unit), basic
flow control, punch cards (inspired by the Jacquard Loom), and
integrated memory. It is the first general-purpose computer
concept. Unfortunately, because of funding issues, this computer
was also never built while Charles Babbage was alive.

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 8


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

The first computer company


The first computer company was Electronic Controls Company and was originated in 1949 by J.
Presper Eckert and John Mauchly, the same individuals who helped create the ENIAC computer.
The company was later renamed to EMCC or Eckert-Mauchly Computer Corporation and released
a series of mainframe computers under the UNIVAC name.

The first digital computer


Short for Atanasoff-Berry Computer, the ABC began development by Professor John Vincent
Atanasoff and graduate student Cliff Berry in 1937. Its development continued until 1942 at
the Iowa State College (now Iowa State University).

The ABC was an electrical computer that used more than 300 vacuum tubes for digital
computation, including binary math and Boolean logic, and had no CPU (was not
programmable). On October 19, 1973, US Federal Judge Earl R. Larson signed his decision that
the ENIAC patent by J. Presper Eckert and John Mauchly was invalid. In the decision, Larson named
Atanasoff the sole inventor.

The ENIAC was invented by J. Presper Eckert and John Mauchly at the University of
Pennsylvania and began construction in 1943 and was not completed until 1946. It occupied
about 1,800 square feet and used about 18,000 vacuum tubes, weighing almost 50 tons. Although
a judge later lined the ABC computer was the first digital computer, many still consider the ENIAC
to be the first digital computer because it was fully functional.

Figure 1.3 [1]

9 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

First computer with a program stored in memory

Figure 1.4 [1]First delivered to the United States


government in 1950, the UNIVAC 1101 or ERA 1101 is
considered the first computer capable of storing and
running a program from memory.

The first microprocessor

Intel introduces the first microprocessor, the Intel 4004, on November 15, 1971.

The Vietnamese-French engineer André Truong Trong Thi and Francois Gernelle developed
the Micral computer in 1973. Considered as the first microcomputer, it used the
Intel 8008 processor and was the first commercial non-assembly computer. It originally sold for
$1,750.

The first personal computer


In 1975, Ed Roberts coined the term "personal computer" when he introduced
the Altair 8800. Although the first personal computer is considered by many to be the KENBAK-
1, which was first introduced for $750 in 1971. The computer relied on a series of switches for
inputting data and output data by turning on and off a series of lights.

Figure 1.5 [1]

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 10


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

The first multimedia computer


In 1992, Tandy Radio Shack released the M2500 XL/2 and M4020 SX, among the first computers
to feature the MPC standard.

Below is a listing of some of the computer company's first computers.

Commodore - In 1977, Commodore introduced its first computer, the "Commodore PET."

Compaq - In March 1983, Compaq released its first computer and the first 100% IBM-compatible
computer, the "Compaq Portable."

Dell - In 1985, Dell introduced its first computer, the "Turbo PC."

Hewlett Packard - In 1966, Hewlett Packard released its first general computer, the "HP-2115."

NEC - In 1958, NEC builds its first computer, the "NEAC 1101."

Toshiba - In 1954, Toshiba introduces its first computer, the "TAC" digital computer.

Definition of Terms

• Desktop computer is a personal computer in a form intended for regular use at a single
location desk/table due to its size and power requirements, as opposed to a laptop whose
rechargeable battery and compact dimensions allow it to be regularly carried and used in
different locations.

• Laptop Computer, sometimes called a notebook computer by manufacturers, is a battery- or


AC-powered personal computer generally smaller than a briefcase that can easily be
transported and conveniently used in temporary spaces such as on airplanes, in libraries,
temporary offices, and at meetings. A laptop typically weighs less than 5 pounds and is 3
inches or less in thickness.

• Tablet Computer, commonly shortened to tablet, is a thin, flat mobile computer with a
touchscreen display, which in 2016 is usually color, processing circuitry, and a rechargeable
battery in a single device. Tablets often come equipped with sensors, including digital
cameras, a microphone, and an accelerometer.

• Smartphone is a mobile phone with an advanced mobile operating system which combines
features of a personal computer operating system with other features useful for mobile or
handheld use.

• Personal Digital Assistant (PDA), also known as a handheld PC, or personal data assistant,is a
mobile device that functions as a personal information manager. The term evolved from

11 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Personal Desktop Assistant, a software term for an application that prompts or prods the user
of a computer with suggestions or provides quick reference to contacts and other lists.

• Compiler is a computer program (or a set of programs) that transforms source code written
in a programming language (the source language) into another computer language (the target
language), with the latter often having a binary form known as object code.

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 12


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Activity No. 1

Introduction:

Computer – A collection of electronic parts that allow software programs to run that perform certain
tasks. A computer can accept input, change data, store data and display data. It contains a rich collection
of terminologies that facilitate its function smoothly.

Objectives:

By the end of activity, the student should be able to:


1. Identify some important terminologies of computers
2. Differentiate each term and give its functions
Procedure(s):

Using the illustration on the next page encircle any 20 computer terminologies from the given word
puzzle.

10 Across
10 Down

F A N O V E N T I L A T I O N A A A G R A P H I C S D R A M
T M O N I T O R F G I O D E V I C E P Q W E R T Y I I O G A
S U I O L N O O M R O M I D E N S M U R R H H T U X R U I N
Y U I D J X A C P U B E Q S G E F E G F B E D E T A B T Y N
G S I E Q W E R T Y R T G P J D T G Y T G R D G S C R E E N
S Y S T E M U N I T E R E R R E H A L T T T Y H E R F R O M
J S U R A X B Y E K E Y B O A R D B A T B Z Y J A R X B T L
Q T W C O M P U T E R E D C O D E Y N C A M E R A A I E E E
Y E I A L L O G S S M A R E R S K T E D B E D E M M T T R D
T M N P I T P I U P I H I S J J E E R G T W I H O P T A A D
A A E S G M T N P E N V V S E A R S Z G E I Y D L A F G B S
B L R L H O I K B A I I E O E M O U S E S F E M E G O R Y T
L I S O T N C C E K S D R R E E U T A J V I Y I D E V E T O
E S S C H I S D E E U E S G T S T G T J C D R I V E E E E R
T A P K I T O R R R P O C O L E P R A P O I N T E R R B S A
Q N P R O O C O C E R C D H S E U F C C O N T R O L L E R G
D M D V D R O M D I U A I F G H T D D P X I D D N T O R G E
V F E G R G T H N H A R D D I S K E V U G E R R F C A E R S
D T R A T E R A F O R D R V R A R V D R F E T O R T D E E J
A Q R T U M O N O C H R O M E T Y R T G T E E M E R G R N M
B U X T M I C R O O M S I E P A T A C O N V E R T E R S S S
D I S K E T T E Y T E X Y V G A C O R D E Q E D C E Q A C T
C X E Q Z O H D M I T U V B X T U V W P O W E R S U P P L Y

13 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

COMPUTERS AND COMPONENTS

Use this image as your reference for the puzzle

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 14


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

COMPUTER TERMINOLOGY

10 Across

Terminology Description

15 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 2: Hardware and Software

Introduction

[2] Computer hardware is any physical device used in or with your machine, whereas
software is a group of programming code installed on your computer's hard drive. In other words,
hardware is something you can hold in your hand, whereas software cannot be held in your hand.
You can touch hardware, but you cannot touch software. Hardware is physical, and software
is virtual.the actual software.

For example, the computer monitor you are using to read this text, and the mouse you
are using to navigate this web page are computer hardware. The Internet browser allowing you
to view this page, and the operating system that the browser is running on are considered
software. A video card is hardware, and a computer game is software. You can touch and feel the
video card, and the computer uses it to play a computer game, but you cannot touch or feel the
programming code that makes up the computer game.

Hardware & Software

• Hardware refers to the physical elements of a computer. This is also sometime called the
machinery or the equipment of the computer. Examples of hardware in a computer are
the keyboard, the monitor, the mouse and the central processing unit. However, most of
a computer's hardware cannot be seen; in other words, it is not an external element of
the computer, but rather an internal one, surrounded by the computer's casing (tower).
A computer's hardware is comprised of many different parts, but perhaps the most
important of these is the motherboard. The motherboard is made up of even more parts
that power and control the computer.

HARDWARES

Are the parts of computer itself including the Central Processing Unit (CPU) and related
microchips and micro-circuitry, keyboards, monitors, case and drives

1. Central Processing Unit


• It refers to the specific chip or processor
• CPUs come in a wild variety of shapes, sizes, socket sets, and architectures

Clock Speed
• determines on how speed the processor perform specific function
• The first computer operates below 30 Megahertz
• The Pentium chips began at 75 MHz in the late 1990's
• Tends to double every year

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 16


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

2. Motherboard
• contains the circuitry and connections that allow the various component to
communicate with each other
• is actually even more central than the Central Processing Unit.
3. Hard Drive
• A Hard drive is a series of magnetic platters on an axle or spindle that stores tiny bits
of magnetic metal in patterns that it can read later
4. Keyboard
• Allows you to input data into your computer. It too can be wired or wireless, PS2 or
USB.
• The standard keyboard has 101 keys.
5. Removable Storage and/or Disk Drives
• disk -is the storage device which contains computer files - or software
• drive -is the mechanism that runs the disk.
6. Optical Drive
• Is a method for taking large amounts of information and storing it on shiny Disks,
like CDs and DVDs.
• Use lasers to read from this media, and in some cases, to write to it.
7. Mouse
The mouse can perform four actions:
• Point:
• Click:
• Double click
• Drag
8. Monitor

Commonly known as a "screen," the monitor gives you a visual display of what your
computer is up to.

a. CRT Monitor
CRT (Cathode Ray Tube) Monitors are built very similarly to older (tube)
television sets.

b. Flatscreen
LCD (Liquid Crystal Display)/ LED (Light Emitting Diode) Monitors are thin
and flat. They are light, compact, take up very little desk space.
9. PRINTER
The printer takes the information on your screen and transfers it to paper or a hard
copy

The three basic types of printer


i. Dot matrix printers

17 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Work like a typewriter transferring ink from a ribbon to paper with a


series or 'matrix' of tiny pins.
ii. Ink jet printers
Work like dot matrix printers but fires a stream of ink from a
cartridge directly onto the paper.
iii. Laser printers
Use the same technology as a photocopier using heat to transfer
toner onto paper.
10. Modems
Is used to translate information transferred through telephone lines, cable or line-
of-site wireless.
11. Scanners
Scanners allow you to transfer pictures and photographs to your computer.
12. CASE
The case houses the microchips and circuitry that run the computer.
13. Expansion Cards
Are components added to computers to increase their capability.

• Software, commonly known as programs or apps, consists of all the instructions that tell
the hardware how to perform a task. These instructions come from a software developer
in the form that will be accepted by the platform (operating system + CPU) that they are
based on. For example, a program that is designed for the Windows operating system will
only work for that specific operating system. Compatibility of software will vary as the
design of the software and the operating system differ. Software that is designed for
Windows XP may experience a compatibility issue when running under Windows 2000 or
NT.

SOFTWARES

• is a general term used to describe the role that computer programs


• Computer instructions or data
• Anything that can be stored electronically

Three Categories of Software

1. Systems software
Includes the operating system and all the utilities that enable the computer to
function.
2. Applications software
Includes programs that do real work for users. For example, word processors,
spreadsheets, and database management systems fall under the category of
applications software.
3. Programming software

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 18


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Usually provides tools to assist a programmer in writing computer programs,


and software using different programming languages in a more convenient way.

SYSTEM SOFTWARE

1. Operating System
Is an interface between hardware and user which is responsible for the
management and coordination of activities and the sharing of the resources of
the computer that acts as a host for computing applications run on the machine.

Example of Operating System


▪ Microsoft Windows
▪ Macintosh
▪ Linux
▪ Solaris

Software User Interface


▪ Command-line Interface(CLI)
is a mechanism for interacting with a computer operating
system or software by typing commands to perform specific
tasks.
▪ Graphical User Interface (GUI)
Offers graphical icons, and visual indicators, as opposed to
text-based interfaces, typed command labels or text
navigation to fully represent the information and actions
available to a user
commonly pronounced “gooey”

2. Utility
Is computer software designed to help manage and tune the computer
hardware, operating system or application software by performing a single task
or a small range of tasks

APPLICATION SOFTWARE

Application software allows end users to accomplish one or more specific (not directly
computer development related) tasks.
▪ Application software
▪ Industrial Automation
▪ Business Software
▪ Computer Games
▪ Databases
▪ Image Editing
▪ Spreadsheet
▪ Word Processing

19 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

PROGRAMMING SOFTWARE

Programming software usually provides tools to assist a programmer in writing


computer programs, and software using different programming languages in a more
convenient way

COMPUTER LANGUAGES

A. Machine Languages
• Is the “natural language” of a particular computer
• It is defined by the hardware design of that computer
• Generally consist of strings of numbers (ultimately reduced to 1’s and 0’s)
that instruct computers to perform their most elementary operation at a
time
B. Assembly Languages
• English-like abbreviations to represent elementary operations
• English-like abbreviations to represent elementary operations
C. High-Level Languages
▪ Single statements could be written to accomplish substantial tasks.

FORTRAN

• FORmula TRANslator
• Was developed by IBM Corporation in the 1950s to be used for scientific and
engineering applications that require complex mathematical computations
COBOL
• Still widely used especially in engineering applications
• Common Business Oriented Language
• Was developed in 1959 by computer manufacturers, the government and industrial
computer users
• Used for commercial applications that require precise and efficient manipulation of
large amount of data
ADA
• A programming language was developed under the sponsorship of the U.S. Department
of Defense (DOD) during 1970s and early 1980s
• Named after Lady Ada Lovelace

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 20


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Evolution of Operating System

OPERATING SYSTEM
Is an interface between hardware and user which is responsible for the management and
coordination of activities and the sharing of the resources of the computer.

EVOLUTION OF OPERATING SYSTEMS


In the early computers there were no Operating Systems

▪ 1960

– commercial computer services and commercial computer merchants started


supplying the extensive apparatus

– University of Waterloo began teaching computer science courses to students in


mathematics, science, and engineering at the undergraduate level.

▪ the advancement of the commercial computer services started the DOS (DISK
OPERATING SYSTEM)

DISK OPERATING SYSTEM


refers to an operating system software used in most computers that provides the abstraction
and management of secondary storage devices and the information on them .

TYPES OF OPERATING SYSTEM SOFTWARE

1. Operating Systems for Single User Systems


2. Operating Systems for Multi User Systems

MULTIPROGRAMMING
Involves the simultaneous operation of many jobs on the computer

TIMESHARING OPERATING SYSTEMS


Is a special case of multiprogramming, in which users access the computer through
terminals (keyboards and screen)

21 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

PERSONAL COMPUTING

These computers were “standalone” units

DISTRIBUTED COMPUTING

Computers are linked together in computer networks, sometimes over telephone lines
(LAN)

CLIENT/ SERVER COMPUTING

Information is shared easily across computer networks

1. File Servers –Offer a common store data that may be used by Client

2. Client-Used collected information from the servers (End-Users)

Programming Software and Updates

HISTORY OF C
Evolved from two previous languages
1. BCPL
2. B

BCPL
(Basic Combined Programming Language)
• Is a computer programming language designed by Martin Richards of the University of
Cambridge in 1967 as a language for writing operation systems Software and compilers.

B language
• Modeled by Ken Thompson after their counterparts in BCPL and used this language in 1970
to create versions of the UNIX operating system at Bell Laboratories on a DEC PDP-7
computer

C language
• Uses many of the important concepts of BCPL and B while adding data typing and other
powerful features
• Initially became widely known as the development language of the UNIX operating system

C Standard Library
• C programs consist of modules or pieces called functions
• You can program all the functions you need to form a C program

2 pieces in learning how to program C


• Learning the C language itself

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 22


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

• Learning how to use the functions in the C standard Library

Advantage and Disadvantage


• In creating your own functions, you will know exactly how they work
• Time-consuming effort that goes into designing and developing new functions
• Using existing functions, you can avoid reinventing the same wheel

C++
• Is a superset of C
• Developed by Bjarne Stroustrup at Bell Laboratories
• Provides a number of features that “spruce up” the C language
• Capable for object-oriented programming

Java
• The name was originated from a coffee place name Java
• Develop by the Sun Microsystems
• It is an internal corporate research project code-named Green in 1991
• The name was originated from a coffee place name Java
• Develop by the Sun Microsystems
• It is an internal corporate research project code-named Green in 1991

BASIC
Beginner’s All-Purpose Symbolic Instruction Code
• was developed in the mid 1960s by professors John Kemeny and Thomas Kurtz of
Dartmount College as a language for writing simple programs
• BASIC’s primary purpose was to familiarize novices with programming techniques

Visual Basic
• Visual Basic was introduced by Microsoft in 1991 to simplify the process of developing
Microsoft Windows applications.

Hardware Trends
• The programming community thrives on a continuing stream of dramatic improvements in
hardware, software and communication technologies

Hardware Trends
• Every year or two, computer performance tends to double while computer prices continue
drop
• Hardware Trends
• Computer System Architecture
• Processors
• Secondary Storage Devices
• Removable Storage Devices
• RAM (Random Access Memory)
• Optical Drives
• Monitors

23 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Internet
• Several research programs started to explore and articulate principles of communications
between physically separate systems, leading to the development of the packet switching
model of digital networking
• It is a network of networks that consists of millions of private, public, academic, business,
and government networks, of local to global scope, that are linked by a broad array of
electronic and optical networking technologies
• Internet is a global system of interconnected computer networks that use the standard
Internet Protocol Suite (TCP/IP) to serve billions of users worldwide
• Internet is a short form of the technical term “internetwork", the result of interconnecting
computer networks with special gateways (routers)
• It is a hardware and software infrastructure that provides connectivity between computers

Cloud
• Also referred to as a network cloud
In telecommunications, a cloud refers to a public or semi-public space on transmission lines
that exists between the end points of a transmission

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 24


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Activity No.2

Introduction:

A computer system consists of two major elements: hardware and software. Computer hardware is the
collection of all the parts you can physically touch. Computer software, on the other hand, is not
something you can touch. Software is a set of instructions for a computer to perform specific operations.

Objectives:

By the end of activity the student should be able to:


1. Identify the parts of the computer hardware
2. Classify computer software
3. Distinguish hardware and software components

Procedure(s):

I. Classify the given software if it is System, Application, Programming or Not Applicable

SOFTWARE EXAMPLES CLASSIFICATION OF SOFTWARE


Operating System
Antivirus
Installer
Image Editing
Games
Hex Screw Driver
Python
B Language
Ink Cartridge
Registry Editor

II. Classify the given computer terms if it is hardware or a software

CLASSIFICATION
Web Browser
Search Engine
Microprocessor
Mouse
Word Processor
Spreadsheet
Cords

25 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Screen
Apps
Operating System

III. Unit Prefixes

PREFIXES MEASUREMENTS
1 000 000 Hertz
1 000 Hertz
2.05 GHz
1.1 GHz
3 150 000 Hertz
1 x 10-3 sec
1 psec
1 usec
1 x 10-9 sec
1 x 10-15 sec

IV. List down 5 different input, output, storage devices


INPUT OUTPUT STORAGE

V. List down 4 hardware and 5 software acronyms and give its description.

Acronym Description
HDD Hard Disk Drive

VI. What is the important functions of software to the computer?


______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________

VII. What is the advantage of using a dot-matrix printer compare to ink jet printer?
______________________________________________________________

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 26


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

______________________________________________________________
______________________________________________________________
______________________________________________________________

VIII. What is the advantages of CLI compare to GUI?


______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
IX. Differentiate data to information.
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________
X. How’s the microcomputer differs from the large-scale computers.
______________________________________________________________
______________________________________________________________
______________________________________________________________

Write A Simple Conclusion:

27 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 3: Classification of Software

Introduction

[3]Software was simple in nature and hence, software development was a simple activity during early
time. However, as technology improved, software became more multifaceted and software projects grew
larger. Software development now necessitated the presence of a team, which could prepare detailed
plans and designs, carry out testing, develop instinctive user interfaces, and integrate all these activities
into a system. This new approach led to the appearance of a discipline known as software engineering.

Classification of Software

[3]Software can be applied in countless fields such as business, education, social sector, and other
fields. It is designed to suit some specific goals such as data processing, information sharing,
communication, and so on. It is classified according to the range of potential of applications. These
classifications are listed below.

System software: This class of software manages and controls the core operations of a
computer system. It is a group of programs, which is responsible for using computer resources
efficiently and effectively. For example, an operating system is a system software, which controls
the hardware, manages memory and multitasking functions, and acts as an interface between
application programs and the computer.

Real-time software: This class of software detects, analyzes, and controls real world events as they
occur. Generally, a real-time system guarantees a response to an external event within a specified period
of time. An example of real-time software is the software used for weather forecasting that collects and
processes parameters like temperature and humidity from the external environment to forecast the
weather. Most of the defense organizations all over the world use real-time software to control their
military hardware.

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 28


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Business software: This class of software is widely used in areas where management and control of
financial actions is of greatest importance. The fundamental component of a business system comprises
payroll, inventory, and accounting software that permit the user to access relevant data from
the database. These activities are usually performed with the help of specialized business software that
facilitates efficient framework in business operations and in management decisions.

Engineering and scientific software: This class of software has emerged as a powerful tool in the
research and development of next generation technology. Applications such as the study of celestial
bodies, under-surface activities, and programming of an orbital path for space shuttles are heavily
dependent on engineering and scientific software. This software is designed to perform precise
calculations on complex numerical data that are obtained during real time environment.

Artificial intelligence (AI) software: This class of software is used where the problem-solving system
is non-algorithmic in nature. The solutions of such problems are generally non-agreeable to computation
or straightforward analysis. Instead, these problems require specific problem-solving strategies that
include expert system, pattern recognition, and game-playing techniques. In addition, they involve
different kinds of search techniques which include the use of heuristics. The role of artificial intelligence
software is to add certain degrees of intelligence to the mechanical hardware in order to get the desired
work done in an agile manner.

Web-based software: This class of software acts as an interface between the user and the Internet. Data
on the Internet is in the form of script, audio, or video format, linked with hyperlinks. Web browser is a
software that retrieves web pages from the Internet. The software incorporates executable instructions
written in special scripting languages such as CGI or ASP. Apart from providing navigation on the Web, this
software also supports additional features that are useful while surfing the Internet.

Personal computer (PC) software: This class of software is used for both official and personal use.
The personal computer software market has grown over in the last two decades from normal text editor
to word processor and from simple paintbrush to advanced image-editing software. This software is used
mainly in almost every field, whether it is database management system, financial accounting package, or
multimedia-based software. It has emerged as a versatile tool for routine applications.

29 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Activity No. 3

Introduction:

Operating Systems are a collection of programs that make the computer hardware conveniently available
to the user and also hide the complexities of the computer's operation. Computer software, or simply
software, is a generic term that refers to a collection of data or computer instructions that tell the
computer how to work, in contrast to the physical hardware from which the system is built, that actually
performs the work.

Objectives:

By the end of activity the student should be able to:


1. Differentiate the computer languages
2. Analyze different software terminologies
3. Draw a simple block diagram

Procedure(s):

I. How does internet browser affect the browse time? Defend your answer.
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________

II. What is the difference between internet and world wide web
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________

III. Differentiate the 3 computer languages and which of those is the most programmer friendly
language?
______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________

IV. Differentiate internet, intranet and extranet.


______________________________________________________________
______________________________________________________________

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 30


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

______________________________________________________________
______________________________________________________________

V. What is the importance of the operating system to the modern computer?


______________________________________________________________
______________________________________________________________
______________________________________________________________
______________________________________________________________

VI. Give the descriptions (All terms are internet related)

Acronyms Descriptions
P2P
HTTP
COPPA
URL
HTML
BW
BITNET
ARPANET
IEN
SSE

VII. Draw a functional Block Diagram

a. Multiprogramming
b. Client to Server Computing
c. Distributed Computing
d. Timesharing Operation

a. Multiprogramming

31 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

b. Client to Server Computing

c. Distributed Computing

d. Timesharing Operation

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 32


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 4: The Number System

Introduction

[4]A number system is defined as a system of writing for expressing numbers. It is the mathematical
notation for representing numbers of a given set by using digits or other symbols in a consistent manner.
It provides a unique representation of every number and represents the arithmetic and algebraic structure
of the figures. It also allows us to operate arithmetic operations like addition, subtraction, and division.

Number System

There are various types of the number system in mathematics. The four most common number
system types are:

1. Decimal number system (Base- 10


2. Binary number system (Base- 2)
3. Octal number system (Base-8)
4. Hexadecimal number system (Base- 16)

Number System Table of Conversion

DECIMAL NUMBERS BINARY NUMBERS OCTAL NUMBERS HEXADECIMAL

0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F

33 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Conversion Procedure

Hexadecimal to Binary
3CF16=_______________2

3 C F

0011 1100 1111

3CF16 = 001111001111 2

9AF16=_______________2

9 A F

1001 1010 1111

9AF16 = 100110101111 2

Hexadecimal to Decimal

3C16 = ____________10

3C16 = 6010

3BE16 = ____________10

3BE16 = 95810

Decimal to Hexadecimal

247910 = _________16

2479 ÷ 16 = 154.9375 (0.9375 x 16 =15=F)

154 ÷ 16 = 9.625 (0.625 x 16 = 10 = A )

9< 16

247910 = 9AF16

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 34


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

643410 = _________16

6434 ÷ 16 = 402.125 (0.125 x 16 =2)

402 ÷ 16 = 25.125 (0.125 x 16=2)

25 ÷ 16 = 1.5625 (0.5625 x 16 = 9)

1 < 16

643410 = 192216

Binary to Decimal

11012 = _________10

1 x 20 = 1

0 x 21 = 0

1 x 22 = 4

1 x 23 = 8

13

11012 = 1310

1112 = _________10

1 x 20 = 1

1 x 21 = 2

1 x 22 = 4

1112 = 710

Decimal to Binary

2410 = __________2

24 ÷ 2 =12 r.=0

12 ÷ 2 = 6 r.=0

35 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

6 ÷ 2 =3 r.=0

3÷2=1 r. = 1

2410 = 110002

Binary to Hexadecimal

0011010101001112 = __________16

[001][1010][1010][0111] = 1AA7

0011010101001112 = 1AA716

111101101112 = __________16

[111][1011][0111] = 7B7

111101101112 = 7B716

Octal to Decimal

758=_______________10

5 x 80 = 5

7 x 81 = 56

5 + 56 = 61

758= 6110

75628 = ____________10

2 x 80 = 2

6 x 81 = 48

5 x 82 = 320

7 x 83 = 3584

3954

75628 = 3954 10

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 36


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Decimal to Octal

20010 = _____________8

200 ÷ 8 = 25 (.0 x 8 = 0 )

25 ÷ 8 = 3 (.125 x 8 = 1)

3<8

20010 = 3108

102310 = _____________8

1023 ÷ 8 = 127 (.875 x 8 = 7 )

127 ÷ 8 = 15 (.875 x 8 = 7)

15 ÷ 8 = 1 (.875 x 8 = 7)

1<8

102310 = 17778

Octal to Binary

758 = ___________2

7 5

111 101

758 = 1111012

75678 = ___________2

7 5 6 7

111 101 110 111

75678 = 1111011101112

37 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Binary to Octal

1111011101112 = ____________8

111 101 110 111

7 5 6 7

1111011101112 = 75678

101010101112 = ____________8

10 101 010 111

2 5 2 7

11010101112 = 25278

Octal to Hexadecimal Conversion

6738 = ___________16

Step 1: Convert first to Binary

6 7 3

110 111 011

Step 2: Then convert Bin to Hex

1 1011 1011

1 B B

6738 = 1BB16

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 38


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Hexadecimal to Octal Conversion

AAA16 = ___________8

Step 1: Convert first to Binary

A A A

1010 1010 1010

Step 2: Then convert Bin to Oct

101 010 101 010

5 2 5 2

AAA16 = 52528

39 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Activity No. 4

Objectives:

By the end of activity, the student should be able to:


1. Convert different number system
2. Use existing number system to represent other number system
3. Develop a short method in converting number systems

Procedure(s):

Convert the following number systems

DECIMALS BINARY OCTAL HEXADECIMALS


ACE

717

101011010

416

111101111

435

CAFE

213

1001010101

318

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 40


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

COMPUTATIONS:

NUMBER SYSTEM CONVERSIONS

1.

2.

3.

4.

5.

41 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

COMPUTATIONS:

NUMBER SYSTEM CONVERSIONS

6.

7.

8.

9.

10.

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 42


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 5: Introduction to Programming

Introduction

[5]You may already have used software, maybe for word processing or spreadsheets, to solve
problems. Perhaps now you are curious to learn how programmers write software. A program is a set of
step-by-step instructions that directs the computer to do the tasks you want it to do and produce the
output you want.

There are at least three good reasons for learning programming:

• Programming helps you know computers. The computer is only a tool. If you learn how to write
simple programs, you will gain more knowledge about how a computer works.
• Writing a few simple programs increases your confidence level. Many people find great personal
satisfaction in creating a set of instructions that solve a problem.
• Learning programming lets you find out quickly whether you like programming and whether you
have the analytical turn of mind programmers need. Even if you decide that programming is not
for you, understanding the process certainly will increase your appreciation of what
programmers and computers can do.

A set of instructions that provides a way of telling a computer what operations to perform is called a
programming language. There is not, however, just one programming language; there are many. In this
chapter you will learn about controlling a computer through the process of programming. You may even
discover that you might want to become a programmer.

The C Compiler

[6]A compiler is a special program that processes statements written in a particular programming
language and turns them into machine language that a computer's processor uses. Typically, a
programmer writes language scripts in a language such as Pascal or C one line at a time using an editor

Offline Compiler

Offline compiler used to be a standalone compiler but not limited to a library package that
enable to run a various computer script, usually need license and some are open source

43 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

a. C Free
i. High level language programming software
ii. Window Base Compiler

Following parts:
1. Main menu and Toolbar
2. Tab bar
3. Code editor
4. Symbol window and Symbol panel
5. Message window
6. File Tree window
7. Status bar

Figure 5.1 Desktop Environment

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 44


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Main Menu and


FILE TREE
Toolbar
TAB BAR WINDOW

CODE EDITOR
SYMBOL WINDOW AND
SYMBOL PANEL

MESSAGE BAR
STATUS BAR

Figure 5.2 Part of C Free

a. Main Menu and Tool Bar

o contains basic commands of file and project operation.


o contains build/execute, help, search and debug.

b. Tab Bar

o Tab bar creates tabs for all opened files, and helps you switch among opened files
quickly

c. Code Editor

45 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

o Code editor locates at the center of main window.


o When opening file, your program code is displayed in code editor, you can write
and modify code in it.

d. Symbol Window/ Symbol Panel


o Symbol Window is contained on the left of code editor
o Functions and variables used in the program are listed here

e. Message Bar
o Shows the messages after compilation

f. File Tree Window


o Symbol Window is contained on the right of code editor
o Display the directory of the file(s)

Online Compiler

Online compiler is a compiler that usually saved at the cloud and can be access only if you are
connected to the network, usually it is free to use and open source.

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 46


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 6: Printing a Line of a Text

Introduction

[7] The C language facilitates a structured and disciplined approach to computer-program design. In this
chapter we introduce C programming and present several examples that illustrate many important
features of C.

A Simple C Program: Printing a line of a text

Example 1.1

1. /* Fig. 2.1: fig02_01.c


2. A first program in C */
3.
4. #include <stdio.h>
5.
6. /* function main begins program execution */
7.
8. int main()
9. {
10. printf( “Computer Programming!\n” );
11.
12. return 0; /* program ended successfully */
13.
14. } /* end function main */

Escape Sequence Description


\n Newline. Position the cursor
at the beginning of the next
line
\t Horizontal tab. Move the
cursor to the next tab stop
\a Alert. Sound the system bell

\\ Backslash. Insert a
backslash character in a
string
\" Double quote. Insert a
double quote character in a
string

47 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Example 1.2

1. /* Example 2 */
2.
3. #include <stdio.h>
4.
5. /* function main begins program execution */
6.
7. int main()
8. {
9. printf( “Computer\nProgramming!\n” );
10.
11. return 0; /* program ended successfully */
12.
13. } /* end function main */

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 48


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Activity No. 6

Introduction:

C is a powerful general-purpose programming language. It is fast, portable and available in all platforms.
If you are new to programming, C is a good choice to start your programming journey. C is a general-
purpose programming language used for wide range of applications from Operating systems like Windows
and iOS to software that is used for creating 3D movies. C programming is highly efficient. That’s the main
reason why it’s very popular despite being more than 40 years old.

Standard C programs are portable. The source code written in one system works in another operating
system without any change.

Objectives:

1. To be able to write simple computer programs in C.


2. To be able to use simple input and output statements.

Procedure(s):

I. Compile the following source code

A.

1. /* Printing multiple lines with a single printf */


2.
3. #include <stdio.h>
4.
5. /* function main begins program execution */
6. int main()
7. {
8. printf("Welcome\nto\nC\Programming!\n");
9.
10. return 0; /* indicate that program ended successfully */
11.} /*end function main */

Output and Explanations:

B.

49 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

1. /* Printing on one line with two printf */


2.
3. #include <stdio.h>
4.
5. /* function main begins program execution */
6. int main()
7. {
8. printf("Welcome ");
9. printf("to C Programming!\n");
10.
11. return 0; /* indicate that program ended successfully */
12.} /*end function main */

Output and Explanations:

II. Give the description of the following escape sequence

ESCAPE SEQUENCE DESCRIPTION

\n\n

\a\a\a

\"\\\\\"

\"\"

\t\t\t

III. Using the techniques you learned, write a program that display these message

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 50


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

a. Display this message using printf

MY FIRST LESSON IN C PROGRAMMING

/*THIS IS A COMMENT*/ PRINTING A LINE OF A TEXT

ESCAPE SEQUENCES USED


\n
\t
\a
\\
\"

C Programming is easy?

b. Display this message using printf

CONVERSION OF NUMBER SYSTEMS

BINARY OCT

0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7

51 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Questions:

1. What are the function of these code:

#include <stdio.h>
______________________________________________

______________________________________________

______________________________________________

int main()
______________________________________________

______________________________________________

______________________________________________

printf
______________________________________________

______________________________________________

______________________________________________

return 0
______________________________________________

______________________________________________

______________________________________________

CONCLUSION: (30pts.)

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 52


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 7: Memory Concept

Introduction

[8] A memory is just like a human brain. It is used to store data and instructions. Computer memory
is the storage space in the computer, where data is to be processed and instructions required for
processing are kept. The memory is divided into large number of small parts called cells. Each location or
cell has a unique address, which varies from zero to memory size minus one.

MEMORY CONCEPT (UNDERSTANDING VARIABLES)

▪ Variable names correspond to locations in the computer’s memory


▪ Every variable has a name, a type and a value

Destructive Read-in

▪ The process of reading information into a memory wherein the value replaces the
previous value in that location

COMMON PROGRAMMING ERROR

▪ An attempt to divide by zero is normally undefined on computer systems and generally results in
a fatal error

▪ Fatal error are errors that causes the program to terminate immediately without having
successfully performed its job

▪ Non-fatal errors allow programs to run to completion, often producing incorrect results

RULES OF OPERATOR PRECEDENCE


▪ Multiplication, division and remainder operation are applied first

▪ Addition and subtraction operations are evaluated next

▪ Evaluation process from left to right (associativity of the operators)

53 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Actvitiy No. 7

Arithmetic Operations in C
Introduction:

Arithmetic Operators in C. The Arithmetic operators are some of the C Programming Operator, which
are used to perform arithmetic operations includes operators like Addition, Subtraction, Multiplication,
Division and Modulus. All these operators are binary operators which means they operate on two
operands

Objectives:

1. To be able to analyse a simple math problems and convert it to C programs


2. To be able to use simple arithmetic operations in C

Procedure(s):

A. (Digits of an Integer) 40 pts. Write a program that inputs a five-digit integer, separates the
integer into its digits and prints them separated by three spaces each. [Hint: Use the integer
division and modulus operators.] For example, if the user types in 11101, the program should
print:

1 1 1 0 1

B. (Diameter, Circumference and Area of a Circle)30pts. Write a program that reads in the radius
of a circle as an integer and prints the circle’s diameter, circumference and area. Use the
constant value 3.14159 for π. Do all calculations in output statements.

C. (Distance, Rate, Time Problem) 30pts. Write a program that reads in the rate and time of the
given body and compute for the distance travelled.

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 54


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Answer Sheet:

A.

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
B.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.

55 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

C.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 56


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 8: Using If and If.. Else Statement

Introduction

[7] If the Boolean expression evaluates to true, then the if block will be executed, otherwise, the
else block will be executed. C programming language assumes any non-zero and non-null values as true,
and if it is either zero or null, then it is assumed as false value.

Discussion

The If Selection Statement


The if selection statement performs an indicated action only when
the condition is true; otherwise the action is skipped.

Example
1. /* Fig.2.13: fig02.13.c
2. Using if statements, relational
3. operators, and equality operators */
4.
5. #include <stdio.h>
6.
7. /*function main begins program execution */
8. int main()
9. {
10. int num1; /*first number to be read from user */
11. int num2; /*second number to be read from user */
12.
13. printf("Enter two integers and I will tell you\n");
14. printf("the relationships they satisfy:\n");
15.
16. scanf("%d%d", &num1, &num2); /*read two integers*/
17.
18. if (num1==num2){
19. printf("%d is equal to %d\n",num1,num2);
20. } /*endif*/
21.
22. if (num1!=num2){
23. printf("%d is not equal to %d\n",num1,num2);
24. } /*endif*/
25.
26. if (num1>num2){
27. printf("%d is greater than %d\n",num1,num2);
28. } /*endif*/

57 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

29.
30. if (num1<num2){
31. printf("%d is less than to %d\n",num1,num2);
32. } /*endif*/
33.
34. return 0;/*indicate that program ended successfully*/
35. } /*end function main*/

The If...else Selection Statement

The if… else selection statements allows the programmer to


specify that the different actions are to be performed when the
condition is true than when the condition is false

Example
1. /* Example 3.2
2. A Grade Program */
3.
4. #include <stdio.h>
5.
6. int main()
7. {
8. int grade;
9.
10. printf("\nThis program will tell you if you passed or failed");
11. printf("the subject\n\n");
12. printf(" \nEnter your grade between (0 to 100): ");
13. scanf("%d",&grade);
14.
15. if (grade>100)
16. printf("\n\nNOT A VALID GRADE!!! \n\n\n");
17. else if (grade==100)
18. printf("\n\nP E R F E C T !!!: Your grade is A\n\n");
19. else if (grade>=89)
20. printf("\n\nPassed: Your grade is A\n\n");
21. else if (grade>=79)
22. printf("\n\nPassed: Your grade is B\n\n");
23. else if (grade>=69)
24. printf("\n\nPassed: Your grade is C\n\n");
25. else if (grade>=59)
26. printf("\n\nPassed: Your grade is D\n\n");
27. else
28. printf("\n\nFAILED ! ! ! \n\n\n");
29.
30. return 0;
31. }

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 58


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Activity No. 8

Objectives:

1. To be able to write a simple program using if and else statements


2. To be able to use simple arithmetic operations in decision making problems

Procedure(s):

A. (Arithmetic, Smallest and Largest) 40 pts. Write a program that inputs three integers from the
keyboard and prints the sum, average, product, smallest and largest of these numbers. The screen
dialog should appear as follows:

Input three different integers: 100 17 14


Sum is 131
Average is 43
Product is 23800
Smallest is 14
Largest is 100

B. (Odd or Even)30 pts. Write a program that reads an integer and determines and prints whether
it’s odd or even. [Hint: Use the modulus operator. An even number is a multiple of two. Any
multiple of two leaves a remainder of zero when divided by 2.]

C. (Multiples)30 pts. Write a program that reads in two integers and determines and prints if the
first is a multiple of the second. [Hint: Use the modulus operator.]

59 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Answer Sheet:

A.

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 60


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

B.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.

C.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.

61 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 9: Formulating Algorithm

Introduction

[9]To make a computer do anything, you have to write a computer program. To write a computer
program, you have to tell the computer, step by step, exactly what you want it to do. The computer then
"executes" the program, following each step mechanically, to accomplish the end goal.

When you are telling the computer what to do, you also get to choose how it's going to do it. That's
where computer algorithms come in. The algorithm is the basic technique used to get the job done.

Discussions

FORMULATING ALGORITHM

Algorithms

A procedure for solving a problem in terms of


• The actions to be executed
• The order in which these actions are to be executed

Control Structures

1. Sequential execution

• Statements in a program are executed one after the other in the order
in which they are written

2. Transfer of control

• Enable the programmer to specify that the next statement to be


executed may be other than the next one in sequence

Pseudocode

• Is an artificial and informal language that helps programmers develop


algorithms.
• The pseudocode is useful for developing algorithms that will be
converted to structured C programs

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 62


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Examples

Example 1:

Pseudocode
1. If student’s grade is greater than or equal to 60
2. Print “Passed”

Equivalent C program
1. if (grade >= 60)
2. printf (“Passed\n”);

Example 2:

Pseudocode
1. If student’s grade is greater than or equal to 60
2. Print “Passed”
3. Else
4. Print “Failed”

Equivalent C Program
1. if (grade >= 60)
2. printf (“Passed\n”);
3. else
4. printf(“Failed\n”);

63 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Actvity No. 9

Objectives:

1. To be able to generate simple loop programs in C.


2. To be able to differentiate the while and for loops.

Procedure(s):

I. Compile the following source code and write the output in the box

A.

1. /* A counter from 1 to 10
2. using while repetition statement */
3.
4. #include <stdio.h>
5.
6. int main()
7. {
8. int counter=1;
9.
10. while(counter<=10)
11. {
12. printf("%d\n",counter);
13. counter=counter+1;
14. }
15.
16. return 0;
17. }

Output and Explanations:

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 64


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

B.

1. /* A countdown from 10 to 1
2. using while repetition statement */
3.
4. #include <stdio.h>
5.
6. int main()
7. {
8. int counter=10;
9. while(counter>=1)
10. {
11. printf("%d\n",counter);
12. counter=counter-1;
13. }
14. return 0;
15. }

Output and Explanations:

II. Give the description of the following operators

OPERATORS DESCRIPTION

==

>

<

>=

<=

65 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

III. Compile the following codes


A.

1. /* A countdown from 1 to 10
2. using for repetition statement */
3.
4. #include <stdio.h>
5.
6. int main()
7. {
8. int counter;
9.
10. for(counter=1;counter<=10;counter++)
11. {
12. printf("%d\t",counter);
13. }
14. printf("\n");
15.
16. return 0;
17. }

Output and Explanations:

B.

1. /* A countdown from 10 to 1
2. using for repetition statement */
3.
4. #include <stdio.h>
5.
6. int main()
7. {
8. int counter;
9.
10. for(counter=10;counter>=1;counter--)
11. {
12. printf("%d\t",counter);
13. }
14. printf("\n");
15.
16. return 0;
17. }

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 66


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Output and Explanations:

Questions:

1. What are the function of these code:

while
______________________________________________

______________________________________________

______________________________________________

for
______________________________________________

______________________________________________

______________________________________________

counter++
______________________________________________

______________________________________________

______________________________________________

counter--
______________________________________________

______________________________________________

______________________________________________

2. What are the difference between while and for repetitions


in looping?

___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
_______________

67 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

3. Write a code using (while and for) utilizing this loop

1
4
9
16
25
36
49
64
81

CODE: (Using while)

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 68


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

CODE: (Using for)

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.

CONCLUSION: (30 pts.)

69 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 10: The General Format Of The For And While Statement

Introduction

While loop executes until the condition turns to false, that is first the condition is checked and if it is true
then body is executed and same continues, but where as in for loop first the variable is intialized if it is
declared and the codition is evaluated and then body of loop finally increment/decrement of variable
happens and same continues.

General Format

for (expression1; expression2; expression3 )


statement
expression1;

while (expression2){
statement;
expression3;

Examples

These two example having the same output but the first one use while loop and the second using for
loop, notice the differences
WHILE LOOP)
1. #include <stdio.h>
2.
3. int main()
4. {
5. int counter=1; /* initialize the counter to 1 */
6.
7. while(counter<=10)
8. {
9. printf("%d\n",counter);
10. counter++; /* increment the counter by 1 */
11. }
12.
13. return 0;
14. }

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 70


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

(FOR LOOP)
1. #include <stdio.h>
2.
3. int main()
4. {
5. int counter; /* initialize the variable counter*/
6.
7. for(counter=1;counter<=10;counter++)
8. {
9. printf("%d\n",counter);
10. }
11.
12. return 0;
13. }

71 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 11: Understanding Algorithm

Introduction

Tasks performed by computers consist of algorithms. An algorithm is a well-defined procedure that


allows a computer to solve a problem. A particular problem can typically be solved by more than one
algorithm. Optimization is the process of finding the most efficient algorithm for a given task.

Objectives

1. To be able to use for repetition for conversion.


2. To be able to understand the concept of looping.
3. To understand the concept of sentinel controlled repetition

Using for loop

[9] How for loop works?


a. The initialization statement is executed only once.
b. Then, the test expression is evaluated. If the test expression is evaluated to false,
the for loop is terminated.
c. However, if the test expression is evaluated to true, statements inside the body
of for loop are executed, and the update expression is updated.
d. Again the test expression is evaluated.
For FlowChart

Figure 11.1 [9]

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 72


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Example using for loop

// Print numbers from 1 to 10


#include <stdio.h>

int main() {
int i;

for (i = 1; i < 11; ++i)


{
printf("%d ", i);
}
return 0;
}

Output

1 2 3 4 5 6 7 8 9 10

i is initialized to 1.

The test expression i < 11 is evaluated. Since 1 less than 11 is true, the body
of for loop is executed. This will print the 1 (value of i ) on the screen.
The update statement ++i is executed. Now, the value of i will be 2. Again, the test
expression is evaluated to true, and the body of for loop is executed. This will
print 2 (value of i ) on the screen.
Again, the update statement ++i is executed and the test expression i < 11 is
evaluated. This process goes on until i becomes 11.
When i becomes 11, i < 11 will be false, and the for loop terminates.

73 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Activity No. 11

Procedure(s):

I. Compile the following source code and write the output on the box
II. Provide a simple explanation for the output

A.

1. /* using for loop for Celsius, Fahrenheit


2. And Kelvin conversion */
3.
4. #include <stdio.h>
5.
6. main()
7. {
8. float c;
9.
10. printf(" Celsius Fahrenheit Kelvin\n");
11.
12. for(c=-40;c<=40;c+=10)
13. printf("%10.2f%10.2f%15.2f\n",c,1.8*c+32,c+273);
14.
15. return 0;
16. }

Output and Explanations:

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 74


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

B.
1. /* using for loop to
2. Convert kilometer to mile */
3.
4. #include <stdio.h>
5.
6. main()
7. {
8. float km;
9.
10. printf("Kilometer Mile\n");
11.
12. for(km=0;km<=40;km+=10)
13. printf("%10.2f%10.2f\n",km,0.621371*km);
14.
15. return 0;
16. }

Output and Explanations:

III. Give the description of the following operators

OPERATORS DESCRIPTION

%10.2f

%15.2f

c+=10

km+=10

km<=40

75 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

IV. Compile the following code

A.

1. /* A sentinel controlled repletion for mi/gallon */


2.
3. #include <stdio.h>
4.
5. int main()
6. {
7. float gallons=0, miles=0, total_gallons=0, total_miles=0;
8. float mpg=0, ompg=0;
9.
10. printf("Enter the gallons used (-1 to end): ");
11. scanf("%f",&gallons);
12.
13. while(gallons!=-1)
14. {
15. total_gallons=total_gallons+gallons;
16. printf("Enter the miles driven: ");
17. scanf("%f",&miles);
18. total_miles=total_miles+miles;
19. mpg=miles/gallons;
20. printf("The miles / gallon for this tank was %f\n\n", mpg);
21. printf("Enter the gallons used (-1 to end): ");
22. scanf("%f",&gallons);
23. }
24.
25. if(total_gallons!=0)
26. {
27. ompg=total_miles/total_gallons;
28. printf("The overall average miles/gallon was %f\n\n", ompg);
29. }
30. else
31. {
32. printf("No gallons were entered\n");
33. }
34.
35. return 0;
36. }

Base on the Item III.A follow the instructions and write the output on the box

a. Input a value for gallon used (any positive value)


b. Input a value for miles driven (any positive value)
c. Input (-1) for gallon used then write the result

OUTPUT

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 76


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Questions:

4. What are the function of these code:

while (gallon != -1)

______________________________________________

______________________________________________

______________________________________________

if (total_gallons!=0)

______________________________________________

______________________________________________

______________________________________________

5. Explain the principle/concept of source code III-A.?

___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
_______________.

6. Write a code using while loop that will compute for the
salary of a given person, given the rate/hour and the
number of hours.

SAMPLE OUTPUT:

Enter the rate/hour(-1 to end),(Php): 100


Enter the number of working hours: 8
Total salary for 8 hrs is: Php 800.00

Enter the rate/hour(-1 to end),(Php): 200


Enter the number of working hours: 5
Total salary for 5 hrs is: Php 1000.00

Enter the rate/hour(-1 to end),(Php): -1

77 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 12: FORMULATING ALGORITHM Case Study

Introduction

[10] A control structure is like a block of programming that analyses variables and chooses a
direction in which to go based on given parameters. The term flow control details the direction the
program takes (which way program control "flows"). Hence it is the basic decision-making process
in computing; It is a prediction.

Algorithm Different Cases

1. CASE STUDY 1 (Counter-Controlled Repetition)


• This technique uses a variable called a counter to specify the number of times a set of
statements should execute
• Is often called definite repetition because the number of repetitions is known before the
loop begins executing

2. CASE STUDY 2 (Sentinel-Controlled Repetition)


• Formulating algorithms with Top-down, Stepwise Refinement
• Is often called indefinite repetition because the number of repetitions is not known before
the loop begins executing.
• One way to solve this problem is to use a special value a sentinel value (also called a signal
value, a dummy value, or a flag value)

3. CASE STUDY 3 (Nested-Controlled Structures)


• A double-selection statement will determine whether each result either option 1 or
option 2
• And will increment the appropriate counters accordingly

ASSIGNMENT OPERATORS

• C provides several assignment operators for abbreviating assignment expressions

c=c+3;

 Can be abbreviated with the addition assignment operator += as

c +=3;

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 78


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

 The += operator adds the value of the expression on the right of the operator to the value of
variable on the left of the operator and stores the result in the variable on the left of the
operator

variable=variable operator expression;

variable operator=expression;

PREINCREMENTING VS. POSTINCREMENTING

Example

1. #include <stdio.h>
2.
3. int main()
4. {
5. int c;
6.
7. c=5;
8. printf("%d\n",c);
9. printf("%d\n",c++);
10. printf("%d\n\n",c);
11.
12. c=5;
13. printf("%d\n",c);
14. printf("%d\n",++c);
15. printf("%d\n",c);
16.
17. return 0;
18. }

PSEUDOCODE

• Is an artificial and informal language that helps programmers develop algorithms


• It is similar to everyday English
• Are not actually executed on computers
• Helps the programmer to think out a program before attempting to write it in a programming
language such as C

FLOW CHART
• Is a graphical representation of an algorithm
• Are drawn using certain special symbols such as ovals, rectangle, diamonds, and small circles
connected by arrows –flowlines

79 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

EXAMPLE (PROBLEM SOLVING)


1. One large chemical company pays its salespeople on a commission
basis. The salespeople receive $200 per week plus 9% of their
gross sales for that week. For example, a salesperson who sells
$5000 worth of chemicals in a week receives $200 plus 9% of
$5000, or a total of $650. Develop a program that will input each
salesperson’s gross sales for last week and will calculate and
display that salesperson’s earnings. Process one salesperson’s
figures at a time.

A. STEP IN CREATING C PROGRAM

• Create an Algorithm
• Create a Pseudocode
• Convert Pseudocode into a C Equivalent Program

B. C Program
1. #include <stdio.h>
2.
3. int main()
4. {
5. float sales=0;
6. float salary=0;
7.
8. printf("Enter sales in dollars (-1 to end):");
9. scanf("%f",&sales);
10.
11. while(sales!=-1){
12.
13. salary=0.09*sales+200;
14. printf("Salary is: %.2f\n",salary;
15. printf("Enter sales in dollars (-1 to
end):");
16. scanf("%f",&sales;
17. }
18.
19. }

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 80


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 13: Break and Continue

Introduction

The break statement allows you to exit a loop from any point within its body, bypassing its normal
termination expression. When the break statement is encountered inside a loop, the loop is immediately
terminated, and program control resumes at the next statement following the loop. The break statement
can be used with all three of C's loops. You can have as many statements within a loop as you desire. It is
generally best to use the break for special purposes, not as your normal loop exit. break is also used in
conjunction with functions and case statements.

Objectives

1. To be able to differentiate the use of break and continue in the loop


2. To learn the purpose of using the break and continue in the loop

Break And Continue Statements


A. Break Statements

 When executed in a while, for, do…while or switch statement,


causes immediate exit from that statement
 Use to escape early from a loop or to skip the remainder of a
switch statement

Example

1. /*Using the break statement in a for statement*/


2. #include <stdio.h>
3. int main()
4. {
5. int x;
6.
7. for (x=1;x<=20;x++){
8.
9. if (x==5){
10. break;
11. }
12. printf("%d ",x);
13. }
14. printf("\nBroke out of loop at x == %d\n",x);
15.
16. return 0;
17.
18. }

81 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

B. Continue Statement

 When executed in a while, for or do…while statement, skips the


remaining statements in the body of that control statement and
performs the next iteration of the loop

Example

1. /*Using the break statement in a for statement*/


2. #include <stdio.h>
3. int main()
4. {
5. int x;
6.
7. for (x=1;x<=20;x++){
8.
9. if (x==5){
10. continue;
11. }
12. printf("%d ",x);
13. }
14. printf("\nUsed continue to skip printing the value 5\n");
15.
16. return 0;
17. }

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 82


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Activity No. 13

I. Compile the following code


A.
1. #include <stdio.h>
2. int main()
3. {
4. int x;
5.
6. for (x=0;x<=200;x+=5){
7.
8. if (x==45){
9. break;
10. }
11. printf("%d\t",x);
12. }
13.
14. return 0;
15.
16. }

OUTPUT:

B.
1. #include <stdio.h>
2. int main()
3. {
4. int x;
5.
6. for (x=0;x<=200;x+=5){
7.
8. if (x==45){
9. continue;
10. }
11. printf("%d\t",x);
12. }
13.
14. return 0;
15.
16. }

OUTPUT:

83 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

II. Question: (10 pts.)

1. What are the differences between the outputs of Program A


to Program B?
___________________________________________________________
___________________________________________________________
___________________________________________________________
____________________________.

CONCLUSION: (30 pts.)

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 84


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 14: Switch Multiple Selections

Introduction

The switch multiple selection statement can be used to perform many different actions based only on a
single integer value. Note however, the switch statement can only be applied in narrow circumstances.
The tests must be constants and be integers.

Objectives

1. To be able to use the switch multiple selection


2. To be able to use the do..while repetition statement
3. To differentiate do…while and while repetition

DO WHILE REPETITION STATEMENT


• Is similar to while statement
• The do…while statement tests the loop after the loop body is
performed.
• The loop body will be executed at least once

do
statement
while (condition);

do {
statement
}while (condition);

Example

1. /*do… while Repetition example*/


2.
3. #include <stdio.h>
4.
5. int main()
6. {
7. int counter=1;
8.
9. do{
10. printf("%d ",counter);
11. counter++;

85 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

12. }while(counter <=10);


13.
14. return 0;
15. }

SWITCH MULTIPLE-SELECTION STATEMENT

Example

1. #include <stdio.h>
2.
3. int main()
4. {
5. int grade;
6. int aCount=0;
7. int bCount=0;
8. int cCount=0;
9. int dCount=0;
10. int fCount=0;
11.
12.
13. printf( "Enter the letter grades. \n" );
14. printf( "Enter the EOF charcter to end input. \n" );
15.
16. while ((grade=getchar())!=EOF){
17. switch (grade){
18. case 'A':
19. case 'a':
20. ++aCount;
21. break;
22.
23. case 'B':
24. case 'b':
25. ++bCount;
26. break;
27.
28. case 'C':
29. case 'c':
30. ++cCount;
31. break;
32.
33. case 'D':
34. case 'd':
35. ++dCount;
36. break;
37.
38. case 'F':
39. case 'f':
40. ++fCount;
41. break;
42.
43. case '\n':

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 86


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

44. case '\t':


45. case ' ':
46. break;
47.
48. default:
49. printf( "Incorrect letter grade entered.");
50. printf( "Enter a new grade.\n");
51. break;
52. }
53. }
54.
55. printf( "\nTotals for each letter grade are:\n");
56. printf("A: %d\n", aCount);
57. printf("B: %d\n", bCount);
58. printf("C: %d\n", cCount);
59. printf("D: %d\n", dCount);
60. printf("F: %d\n", fCount);
61.
62. return 0;
63. }

87 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Activity No. 14

I. Write a switch multiple selection statement to count the following grades

Description:
The program will ask any letters from A to D and it will print a message according to the
letter entered. If (A) is pressed it will print (100). If (B, C and D) it will print (90,80 and 70)
respectively. If other letters it will print Non-Catergorized.

A Print 100
B Print 90
C Print 80
D Print 70
Other Letters Non-Categorized

Write your program here:

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 88


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

33.
34.
35.
36.
37.
38.
39.
40.

II. Write a program using do...while to display the following sequence of number using 1 variable
only

2 20 200
4 40 400
6 60 600
8 80 800
10 100 1000
12 120 1200
14 140 1400
16 160 1600
18 180 1800
20 200 2000

Write your program here:

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.

89 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

III. What is the difference between using while repetition compare to do...while repetition?
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________.

IV. What are the disadavantages of using switch case multiple selection compare to the other loop
codes?
_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
_________________________________.

Conclusion: (30pts.)

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 90


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 15: Functions

Introduction

In c, we can divide a large program into the basic building blocks known as function.
The function contains the set of programming statements enclosed by {}. A function can be called multiple
times to provide reusability and modularity to the C program.

C mathematical operations are a group of functions in the standard library of the C programming
language implementing basic mathematical functions. The math.h header defines various mathematical
functions and one macro. All the functions available in this library take double as an argument and return
double as the result.

C Standard Library

▪ Provides a rich collection of functions for performing common mathematical calculations, string
manipulation, character manipulation, input/output, and many other useful operations

▪ The functions printf, scanf and pow are standard library functions

Programmer-defined functions
▪ The programmer can write functions to define specific task that may be used at many points in a
program

Math Library Functions


▪ Functions are normally used in a program by writing the name of the function followed by a left
parenthesis followed by the argument of the function followed by a right parenthesis

printf("%.2f",sqrt(900.0));

▪ Include the math header by using the preprocessor directive #include <math.h> when using
functions in the math library

91 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

THE MATH LIBRARY FUNCTIONS


FUNCTIONS DESCRIPTION
sqrt(x) Square root of x
exp(x) Exponential
function
log(x) Natural
logarithm of x
log10(x) Logarithm of x
(Base 10)
fabs(x) Absolute value
of x
ceil(x) Round x to the
smallest integer
not less than x
floor(x) Round x to the
largest integer
not greater than
x
pow(x,y) X raise to the
power of y
fmod (x,y) Remainder of x/y
as a floating
point number
sin(x) Trigonometric
sin of x in
radians
cos(x) Trigonometric
cosine of x in
radians
tan(x) Trigonometric
tangent of x in
radians

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 92


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 16: Math Library Functions

Introduction:

C mathematical operations are a group of functions in the standard library of the C programming language
implementing basic mathematical functions. The math.h header defines various mathematical functions
and one macro. All the functions available in this library take double as an argument and return double as
the result.

Objectives

1. To be able use the library function for math problems


2. To be able to combine the math library functions and sentinel controlled repetition

Example

1. /*The math library function */


2.
3. #include <stdio.h>
4. #include <math.h>
5.
6. int main()
7. {
8. float number;
9. printf("Enter a valid number:\t");
10. scanf("%f",&number);
11.
12. printf("MATH OPERATION:\n\n");
13. printf("The square root is: %.2f\n",sqrt(number));
14. printf("The natural logarithm is: %.2f\n",log(number));
15. printf("The logarithm is: %.2f\n",log10(number));
16. printf("The square is: %.2f\n",pow(number,2));
17.
18. return 0;
19. }

93 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Activity No. 16

Programming: (100 pts.)

a. Write a program that will compute for the roots of a 2nd


degree equation.

Following a certain condition


a. Any roots with imaginary answer must be classified as
imaginary roots
b. Non-quadratic equation must be classified as non-
quadratic.
c. Must be terminated by a sentinel

*Write your code at the answer sheet on the next page

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 94


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Answer Sheet:

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.

95 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 17: RANDOM NUMBER GENERATIONS

Introduction

The C library function int rand(void) returns a pseudo-random number in the range of 0 to RAND_MAX.
RAND_MAX is a constant whose default value may vary between implementations but it is granted to be
at least 32767.

Objectives

1. To be able to use the math standard library to solve for some mathematical calculation
2. To be able to use the standard library to generate a pseudorandom numbers and a srand
function
3. To use the math and random function for some application

Rand function

The rand function generates an integer between 0 and RAND_MAX (a symbolic constant defined in the
<stdlib.h> header.

If rand truly produces integers at random, every number between 0 and RAND_MAX has an equal
chance of being chosen each time rand is called.

Example
1. /*Shifted, scaled integers produced by 1 + rand() % 6 */
2.
3. #include <stdio.h>
4. #include <stdlib.h>
5.
6. /* Function main begins program execution */
7.
8. int main()
9. {
10. int i;
11.
12. for (i=1;i<=20;i++)
13. {
14. printf("%10d",1+(rand()%6));
15.
16. if(i%5==0)

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 96


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

17. {
18. printf("\n");
19. }
20. }
21.
22. return 0;
23. }

97 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Activity No. 17

Compile the following source code

A.

1. /* Math library Function */


2.
3. #include <stdio.h>
4. #include <math.h>
5.
6. int main()
7. {
8. float number;
9.
10. printf("Enter a valid number: ");
11. scanf("%f",&number);
12.
13. printf("\n");
14. printf("Sqrt(%.2f) = %.2f\n",number,sqrt(number));
15. printf("Exp(%.2f) = %.2f\n",number,exp(number));
16. printf("Ln(%.2f) = %.2f\n",number,log(number));
17. printf("Log(%.2f) = %.2f\n",number,log10(number));
18. printf("Ceil(%.2f) = %.2f\n",number,ceil(number));
19. printf("Floor(%.2f) = %.2f\n",number,floor(number));
20.
21.
22. return 0;
23. }
24.

Output (Press any floating number as a entry):

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 98


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

B. Using the program at I.A, complete the following table

Number Sqrt Exp Ln Log Floor Ceil

4.01

5.25

2.12

1.40

0.60

I. Compile the following source code

A.
1. #include <stdio.h>
2. #include <stdlib.h>
3.
4. int main(){
5. int i;
6.
7. for(i=1;i<=30;i++){
8. printf("%d\t",5+(rand()%20));
9.
10. if (i%5==0)
11. printf("\n");
12. }
13. return 0;
14. }

Output:

99 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

B. Using rand()_shifting and rand()_scaling , complete the table


below to generate the range of the following random numbers

Rand()_shifting and POSSIBLE OUTPUT


Rand()_scaling
1+rand()%2 1-2

0-32767

1-4

6-10

49-100

57-77

999-1110

2110-2111

76-80

1001-1500

2,4,6,8,10

II. Programming:

a. Write a program that will generate 10 random numbers on the


1st column, square root of the generated 10 random numbers
on the 2nd column, floor function on the 3rd column and ceil
function on the 4th column.
b. Write a program that will generate 5 columns, 200 real-
random numbers that ranges from 125-500.

CONCLUSION: (30 pts.)

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 100


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Week 18: Application of C in Solving Engineering Formulas

Introduction

Engineering Approach contains almost unlimited formulas that solve different scientific problems.
And it takes a lot of calculation in proving laws and theorems. Using a software based application aids
engineers and researchers to validate and speed up data gathering and processes, one of the powerful
computer language that they used is the C language.

Objectives

1. To create a program using C language that can calculate engineering formulas


2. To write a program that use different commands in C

101 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

Laboratory Activity No. 18

Write any Engineering Formula Calculator that use all the following commands
a. If and If… Else
b. While or For Loops
c. A Sentinel Controlled Loop
d. A Math Functions not less than 5 functions

COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE 102


UNIVERSITY OF NUEVA CACERES COLLEGE OF ENGINEERING AND ARCHITECTURE

References

[1] "https://www.computerhope.com/jargon/c/computer.htm," [Online].

[2] "https://www.computerhope.com/issues/ch000039.htm," [Online].

[3] "https://ecomputernotes.com/software-engineering/characteristics-and-classification-of-
software," [Online].

[4] "https://byjus.com/maths/number-system/#what-is-number-system," [Online].

[5] "https://homepage.cs.uri.edu/faculty/wolfe/book/Readings/Reading13.htm," [Online].

[6] "https://whatis.techtarget.com/definition/compiler," [Online].

[7] D. &. A. I. Paul Deitel, "C How to Program," in C How to Program, 10th Edition, 2017.

[8] "https://www.tutorialspoint.com/computer_fundamentals/computer_memory.htm," [Online].

[9] "https://computer.howstuffworks.com/what-is-a-computer-algorithm.htm," [Online].

[10] "https://en.wikiversity.org/wiki/Control_structures," [Online].

[11] "https://www.programiz.com/c-programming/c-for-loop," [Online].

[12] "https://en.wikiversity.org/wiki/Control_structures," [Online].

103 COMPUTER AIDED DRAFTING v.1.0 BY JAMES FRANCIS B. AGUILAR, ECE

You might also like