0% found this document useful (0 votes)
82 views9 pages

Workbook (6 Lesson Plan)

1. Programming languages allow computers to perform tasks by using a structured set of basic elements and rules to combine them. Common programming languages include C, Java, Ruby, and Perl. Programs typically have input, processing, and output components. 2. The document provides examples of simple C++ programs that output text, perform arithmetic operations, take user input, and demonstrate various programming concepts like comments, variables, and operators. 3. The document shifts to discussing problem solving exercises in Russian, with examples of programs that calculate the next/previous number, divide apples among students, and find the last digit or tens place of numbers.

Uploaded by

Khisrav
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)
82 views9 pages

Workbook (6 Lesson Plan)

1. Programming languages allow computers to perform tasks by using a structured set of basic elements and rules to combine them. Common programming languages include C, Java, Ruby, and Perl. Programs typically have input, processing, and output components. 2. The document provides examples of simple C++ programs that output text, perform arithmetic operations, take user input, and demonstrate various programming concepts like comments, variables, and operators. 3. The document shifts to discussing problem solving exercises in Russian, with examples of programs that calculate the next/previous number, divide apples among students, and find the last digit or tens place of numbers.

Uploaded by

Khisrav
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/ 9

1.

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.

The First C++ Program


It is time to type our first C++ program. This program is going to prompt a line of text
that says "Hello World!". This program has no input and no process but only output
which says "Hello world!".
#include <iostream>
using namespace std;
int main ()
{
cout << “Hello Class!”;
system(“pause”);
return 0;
}
Hello world!Press any key to continue . . .
Breaking a Text into Multiple Lines
Use end of line "endl" with in a cout statement to make a new line.
#include <iostream>
using namespace std;
int main()
{
cout <<"Hello world!"<<endl;
cout <<"This is my C++ program."<<endl<<endl;
system("pause");
return 0;
}
Hello world!
This is my C++ program.
Press any key to continue . . .

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 

Задача 3.1 - Следующее и предыдущее


Напишите программу, которая считывает целое число и выводит текст, аналогичный приведенному в
примере. Пробелы, знаки препинания, заглавные и строчные буквы важны!

Пример

Ввод Вывод
179 The next number for the number 179 is 180.
The previous number for the number 179 is 178.

Задача 3.2 - Дележ яблок


N школьников делят K яблок поровну, неделящийся остаток остается в корзинке. Сколько яблок
достанется каждому школьнику? Программа получает на вход числа Nи K и должна вывести искомое
количество яблок.

Пример

Ввод Вывод
3 4
14

Задача 3.3 - Последняя цифра


Дано натуральное число. Выведите его последнюю цифру.

Пример

Ввод Вывод
179 9
4. Lesson
Solving Problems - 2

Задача 4.1 - Число десятков двузначного числа


Дано двузначное число. Найдите число десятков в нем.

Пример

Ввод Вывод
42 4

Задача 4.2 - Число десятков


Дано натуральное число. Найдите число десятков в его десятичной записи (то есть вторую справа
цифру его десятичной записи).

Пример

Ввод Вывод
179 7

Задача 4.3 Сумма цифр


Дано трехзначное число. Найдите сумму его цифр.

Пример

Ввод Вывод
179 17
5. Lesson
Solving Problems - 3

Задача 5.1 - Электронные часы


N: Электронные часы - 1

Дано число n. С начала суток прошло n минут. Определите, сколько часов и минут будут показывать
электронные часы в этот момент. Программа должна вывести два числа: количество часов (от 0 до
23) и количество минут (от 0 до 59). Учтите, что число n может быть больше, чем количество минут
в сутках.

Пример

Ввод Вывод

150 2 30
1441 0 1

Задача 5.2 - Следующее четное


Дано целое число n. Выведите следующее за ним четное число. При решении этой задачи нельзя
использовать условную инструкцию if и циклы.

Пример

Ввод Вывод
7 8
8 10

Задача 5.3 - Конец уроков


В некоторой школе занятия начинаются в 9:00. Продолжительность урока — 45 минут, после 1-го, 3-
го, 5-го и т.д. уроков перемена 5 минут, а после 2-го, 4-го, 6-го и т.д. — 15 минут.

Дан номер урока (число от 1 до 10). Определите, когда заканчивается указанный урок. Выведите два
целых числа: время окончания урока в часах и минутах. При решении этой задачи нельзя
пользоваться циклами и условными инструкциями.

Пример

Ввод Вывод
3 11 35
2 10 35
6. Lesson
Solving Problems – 4

Задача 6.1 - Стоимость покупки


Пирожок в столовой стоит a рублей и b копеек. Определите, сколько рублей и копеек нужно
заплатить за n пирожков. Программа получает на вход три числа: a, b, n и должна вывести два числа:
стоимость покупки в рублях и копейках.

Пример

Ввод Вывод
10 20 30
15
2
2 10 0
50
4

Задача 6.2 - Разность времен


Даны значения двух моментов времени, принадлежащих одним и тем же суткам: часы, минуты и
секунды для каждого из моментов времени. Известно, что второй момент времени наступил не
раньше первого. Определите, сколько секунд прошло между двумя моментами времени. Программа
на вход получает три целых числа — часы, минуты, секунды, задающие первый момент времени и
три целых числа, задающих второй момент времени. Выведите число секунд между этими
моментами времени.

Пример

Ввод Вывод
1 3661
1
1
2
2
2
1 50
2
30
1
3
20

You might also like