Workbook (6 Lesson Plan)
Workbook (6 Lesson Plan)
Lesson
Programming Languages
To tell your computer how to do something, you must use a programming language.
A programming language is similar to a human language in that it’s made up of basic
elements (such as nouns and verbs) and ways to combine those elements to create
meaning (sentences, paragraphs, and novels). There are many languages to choose
from (C, Java, Ruby, Perl...), and some have a larger set of those basic elements than
others.
A computer program (software) contains a sequence of instructions for a computer.
One program is usually composed of three parts:
Input part gets the data from an input device. Our programs, in the book, will get
the data from keyboard or from a text file.
Process part is the hardest working part of the program. It carries out the
algorithm and finds out the desired result.
Output part gives the result of the program. Our programs will display the result
on the screen or print it into a text file.
Basic Arithmetic
Any statement enclosed with double quotes (" ") in a cout statement is displayed
directly and any arithmetical or logical expression is evaluated and then the result is
displayed. The program below shows the result of the expression 3 + 5.
#include <iostream>
using namespace std;
int main()
{
cout <<"5 + 3 = "<<5+3<<endl;
system("pause");
return 0;
}
5+3=8
Press any key to continue . . .
2. Lesson
Getting Data from the User (Input)
Programs usually read the input data from the standard input (keyboard) or from an
input file. "cin" command is used to read data from the standard input. The following
program reads two integers, calculates their sum and then outputs the result.
int num1, num2, sum; declares three variables. The names of the variables are num1,
num2 and sum. A variable is a named storage location that can contain data that can be
modified during program execution. This declaration specifies that those variables can
contain integer values (-45, 0, 11, 37, etc.). "num1" and "num2" will be used to store the
input data, and "sum" will be used to keep the sum of input values in the program.
#include <iostream>
using namespace std;
int main()
{
int num1, num2, sum;
cout<<"Enter two integers:"<<endl;
cin >> num1 >> num2;
sum = num1 + num2;
cout <<"Sum is "<<sum<<endl;
system("PAUSE");
return 0;
}
Enter two integers:
57
Sum is 12
Press any key to continue . . .
Arithmetic Operators
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
cout <<"Enter two integers:";
cin >> num1 >> num2;
cout <<num1 <<"+"<<num2<<"="<<num1+num2<<endl;
cout <<num2 <<"+"<<num1<<"="<<num2+num1<<endl<<endl;
cout <<num1 <<"-"<<num2<<"="<<num1-num2<<endl;
cout <<num2 <<"-"<<num1<<"="<<num2-num1<<endl<<endl;
cout <<num1 <<"*"<<num2<<"="<<num1*num2<<endl;
cout <<num2 <<"*"<<num1<<"="<<num2*num1<<endl<<endl;
cout <<num1 <<"/"<<num2<<"="<<num1/num2<<endl;
cout <<num1 <<"/"<<num2<<"="<<(float)num1/num2<<endl;
cout <<num2 <<"/"<<num1<<"="<<num2/num1<<endl;
cout <<num2 <<"/"<<num1<<"="<<(float)num2/num1<<endl<<endl;
cout <<num1 <<"%"<<num2<<"="<<num1%num2<<endl;
cout <<num2 <<"%"<<num1<<"="<<num2%num1<<endl<<endl;
system("PAUSE"); return 0;
}
Enter two integers: 7 3
7+3=10
3+7=10
7-3=4
3-7=-4
7*3=21
3*7=21
7/3=2
7/3=2.33333
3/7=0
3/7=0.428571
7%3=1
3%7=3
Press any key to continue . . .
3. Lesson
Solving Problems - 1
Problems are in Russian language, so if you have some troubles with understanding
please ask for help from someone whose Russian is good!
If your problems become big, contact Alexandr Ismatov by phone or email
Пример
Ввод Вывод
179 The next number for the number 179 is 180.
The previous number for the number 179 is 178.
Пример
Ввод Вывод
3 4
14
Пример
Ввод Вывод
179 9
4. Lesson
Solving Problems - 2
Пример
Ввод Вывод
42 4
Пример
Ввод Вывод
179 7
Пример
Ввод Вывод
179 17
5. Lesson
Solving Problems - 3
Дано число n. С начала суток прошло n минут. Определите, сколько часов и минут будут показывать
электронные часы в этот момент. Программа должна вывести два числа: количество часов (от 0 до
23) и количество минут (от 0 до 59). Учтите, что число n может быть больше, чем количество минут
в сутках.
Пример
Ввод Вывод
150 2 30
1441 0 1
Пример
Ввод Вывод
7 8
8 10
Дан номер урока (число от 1 до 10). Определите, когда заканчивается указанный урок. Выведите два
целых числа: время окончания урока в часах и минутах. При решении этой задачи нельзя
пользоваться циклами и условными инструкциями.
Пример
Ввод Вывод
3 11 35
2 10 35
6. Lesson
Solving Problems – 4
Пример
Ввод Вывод
10 20 30
15
2
2 10 0
50
4
Пример
Ввод Вывод
1 3661
1
1
2
2
2
1 50
2
30
1
3
20