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

2023 Slide Deck - ITPPA1-22 - Week - 2

The document discusses procedural programming and introduces variables, data types, arithmetic operators, precedence and expressions, variable assignment, and input statements. It explains how to create a basic C++ program with functions, special symbols, identifiers, comments, and input/output. The lesson covers the basic building blocks for designing programs in C++.

Uploaded by

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

2023 Slide Deck - ITPPA1-22 - Week - 2

The document discusses procedural programming and introduces variables, data types, arithmetic operators, precedence and expressions, variable assignment, and input statements. It explains how to create a basic C++ program with functions, special symbols, identifiers, comments, and input/output. The lesson covers the basic building blocks for designing programs in C++.

Uploaded by

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

Procedural Programming

ITPPA1-22

Eduvos (Pty) Ltd (formerly Pearson Institute of Higher Education) is registered with the Department of Higher Education and Training as a private higher education institution under the
Higher Education Act, 101, of 1997. Registration Certificate number: 2001/HE07/008
Week 2: Lesson 4 & 5
Introduction

Designing a Program, Variables and Input


• Become familiar with the basic components of a C11 program, including functions, special
symbols, and identifiers

• Explore simple data types

• Discover how to use arithmetic operators

• Become familiar with the string data type

• Learn what an assignment statement is and what it does

• Discover how to input data into memory using input statements

• Explore how to properly structure a program, including using comments to


• document a program

• Learn how to write a C11 program


What will be covered
in today’s lesson?
In this chapter, you will learn the basics of
C++.

Week 2 Data types, Variables, and


Assignments
Lesson 4
Arithmetic operators, Precedence
&5 and expressions

Variable assignment, and Input


statements

Creating a C++ program


Problem-Based Learning

What is the difference between a reserved


word and a user-defined identifier?

Discuss recommendations for defining user


variables.

Discuss the main components of a C++


program? What is the role of the compiler?
Questions for Discussion

Discuss whether the following are valid C++ identifiers?

CPP_Assignment firstC++Prog

InchesInOneCentimeter travel_Time

Monthly Pay 3feetInAYard

Jack’sHomework _number
Activity
1. Mark the following statements as true or
false.
a. An identifier must start with a letter and can
be any sequence of
characters. (1)
b. In C11, there is no difference between a
reserved word and a
predefined identifier. (1)
c. A C11 identifier cannot start with a digit. (1)
d. The collating sequence of a character is its
preset number in the
character data set. (2)
e. Only one of the operands of the modulus
operator needs to be of
type int. (3)
Activity

1. Evaluate the following expressions.


a. 25 + 4 - 7
b. 8 / 3
c. 13 / 3 * 6 - 10
d. 3 + 5 % 6
e. 28 / 4.0
f. 20 - 13 % 2 + 18 / 9
g. 42 % 36 - 6 + 36 / 7 * 4
h. 5 / 9 * (32.6 – 4.5)
i. 13.5 + 2.0 * 4.0 / 4.0
Activity

If int x = 10;, int y = 7;, double z =


4.5;, and double w = 2.5;
evaluate each of the following statements, if
possible. If it is not possible, state the reason.
a. (x + y) % x
b. x % y + w
c. z - y) / w
d. (y + z) % x
e. (x % y) * z
f. x % y % 2
g. (x + y) % z
h. (x % y + z) / w
Activity
1. Write C++ statements that accomplish the following.
(6, 7)
a. Declare int variables x and y. Initialize x to 25 and y to
18.
b. Declare and initialize an int variable temp to 10 and a
char
variable ch to 'A'.
c. Update the value of an int variable x by adding 5 to it.
d. Declare and initialize a double variable payRate to
12.50.
e. Copy the value of an int variable firstNum into an int
variable
tempNum.
f. Swap the contents of the int variables x and y. (Declare
additional
variables, if necessary.)
g. Suppose x and y are double variables. Output the
contents of x, y,
and the expression x + 12 / y – 18.
h. Declare a char variable grade and set the value of grade
to 'A'.
i. Declare int variables to store four integers.
j. Copy the value of a double variable z to the nearest integer
into
an int variable x.
Activity
Write each of the following as a C++ expression.
a. 9.0 divided by 5 times C plus 32.
b. The integer value of the character +.
c. Round the decimal number x to the nearest integer.
d. Assign the string C++ Programming is
exciting to the
variable str.
e. Assign the value of 12 times feet plus inches
to totalInches.
f. Increment the value of the int variable i by 1.
g. v = 4/3(3.1416r3).
h. s = 2(3.1416r2) + 2(3.1416r)h.
i. a +(b–c)/d(ef – gh)
j. (-b + (b2 - 4ac)) / 2a
Activity
Write a program that produces the following output:
**********************************
* Programming Assignment 1 *
* Computer Programming I *
* Author: ??? *
* Due Date: Thursday, Jan. 24 *
**********************************
In your program, substitute ??? with your own name. If
necessary, adjust the positions and the number of the stars
to produce a rectangle.
Activity
1. Consider the following program segment:
//include statement(s)
//using namespace statement
int main()
{
//variable declaration
//executable statements
//return statement
}
a. Write a C++ statement that includes the header file iostream.
b. Write a C++ statement that allows you to use cin, cout, and endl
without the prefix std::.
c. Write C++ statement(s) that declare the following variables: num1,
num2, num3, and average of type int.
d. Write C++ statements that store 125 into num1, 28 into num2, and
-25 into num3.
e. Write a C++ statement that stores the average of num1, num2, and
num3 into average.
f. Write C++ statement(s) that output the values of num1, num2,
num3, and average.
g. Compile and run your program.
What Happens Next?
Prepare Chapter 6: User-defined functions for next week.
Prepare the work on myLMS under week 3: Modular design.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy