RomanF
romanF отличник
2013-01-10T16:13:22+00:00
1. Подумать над алгоритмом
2. Вот сам алгоритм:
а. спросить у пользователя значения
б. расчитать ответ
в. выдать ответ на экран
3. Написать код в паскале
4. Исправить ошибки компиляции
5. Протестировать, вводить разные числа
6. обнаружила, что если вводить числа наугад ответ получается отрицательным иногда
7. Вставить код проверки введенных пользователем значений
8. убрать ошибки компиляции
9. протестировать
10. готово
А вот и сама программа:
program aerobus;
uses crt;
const TotalPlace = 160;
var businessPlaces, economyPlaces:integer;
businessPrice, economyPrice:real;
totalCharge:real;
a,b:integer;
correctInput:boolean;
begin
clrscr;
businessPlaces:=TotalPlace div 4;
economyPlaces:= TotalPlace - businessPlaces;
writeln('business places count: ', businessPlaces);
writeln('economy places count: ', economyPlaces);
correctInput:=false;
while not correctInput do
begin
write('Please Input Business Class Ticket Price: ');
readln(businessPrice);
if(businessPrice>0) then
begin
correctInput:=true;
end
else
begin
writeln('The price should be a positive number, please try again');
end;
end;
economyPrice:=businessPrice/2;
writeln('Economy Ticket Price is: ', economyPrice:0:2);
correctInput:=false;
while not correctInput do
begin
write('How many business tickets are left?: ');
readln(a);
if(a>=0) and (a<=businessPlaces)then correctInput:=true;
if(a<0) then
begin
writeln('Please input a positive number or 0, please try again');
end;
if(a>businessPlaces) then
begin
writeln('Please input a number which is less or equal to the tolal business place count, please try again');
end;
end;
correctInput:=false;
while not correctInput do
begin
write('How many economy tickets are left?: ');
readln(b);
if(b>=0) and (b<=economyPlaces)then correctInput:=true;
if(b<0) then
begin
writeln('Please input a positive number or 0, please try again');
end;
if(b>economyPlaces) then
begin
writeln('Please input a number which is less or equal to the tolal economy place count, please try again');
end;
end;
totalCharge:=(businessPlaces-a)*businessPrice;
totalCharge:=totalCharge+(economyPlaces-b)*economyPrice;
writeln('The total charge is:', totalCharge:0:2);
writeln;
writeln('Press enter to exit');
readln;
end.
Ответ:
2,0,334
Объяснение:
Описываем две пользовательские функции в Excel VBA:
Function newstr(str As String, n As Integer) As String
Dim i As Integer
For i = 1 To n
str = Replace(str, "a", "ab")
str = Replace(str, "bb", "c")
Next
newstr = str
End Function
Function chrcount(str1 As String, str2 As String) As Integer
Dim str() As String
str = Split(str1, str2)
chrcount = UBound(str, 1)
End Function
С рабочего листа вызываем функцию:
= chrcount(newstr("abab"; 333); "a")&","&chrcount(newstr("abab"; 333); "b")&","&chrcount(newstr("abab"; 333); "c")
Получаем результат:
2,0,334
Uses crt;
var a,b,c : integer;
begin
writeln('Введите a (c<a*b)');
readln(a);
writeln('Введите b (c<a*b)');
readln(a);
writeln('Введите c (c<a*b)');
readln(a);
repeat
c = c*2;
until c > a*b;
writeln(a,b,c);
10101010(2) =170(10)
Решение:
Приведем 10101010 из системы счисления 2 в десятичную систему счисления
101010102=1·2(7) +0·2(6) +1·2(5) +0·2(4) +1·2(3) +0·2(2) +1·2(1) +0·2(0) =170(10)
252(8) =170(10)
Приведем 252 из системы счисления 8 в десятичную систему счисления
252(8)=2·8(2) +5·8(1) +2·8(0) =170(10)
7(16) =7(10)
Приведем 7 из системы счисления 16 в десятичную систему счисления
7(16)=7·16(0) =7(10)
170(10) - 170(10) + 7(10) = 7(10)
В идентификаторе 2 буквы и 8 цифр.
Мощность алфавита букв равна 18, для кодирования 1 буквы требуется 5 бит, т.к. 2^5=32 (четырёх бит недостаточно).
Для кодирования 1 цифры требуется 4 бита, т.к. всего 10 цифр, 2^4 = 16 (чего достаточно для хранения 10 цифр, в отличие от 3-х бит).
Объем одного пароля равен 2*5+8*4 = 10+32 = 42 бит
42 : 8 = 6 Байт (пяти байт недостаточно).
25 * 6 = 150 байт.