Программирование >>  Расширенная версия языка c++ 

1 ... 197 198 199 [ 200 ] 201 202 203 ... 227


Cjmo учитель C++

int mainO

char str[80];

ci alpha str; cout str \d ;

return 0;

3. Копирование файла и смена регистра букв ttinclude <iostream> ttinclude <fstream> ttinclude <cctype>

using namespace

in (int argc, char *argv[])

char ch;

if(argc!=3) I

cou <., Копирование <источник> <целевой файл>\п ;

return 1;

ifstreamin{argv[l] ) ; if(!in) {

cou << Файл ввода открыть невозможно\п ;

return

ofstream out(argv[2]) ; if(lout) {

cou< Файл вывода открыть невоэможно\п ;

return

ch = in. get ( ) ; . if (!in.eof() ) { i-.jc:.-

ch =

else ch = out.put(ch);

in.close () ; out. closJ ;



Приложение В. Ответы носы и решения упражнений 607

return 0;

4. Подсчет букв ttinclude <iostreaiii> ttinclude <f3treain> ttinclude <cctype> using naiaespace std;

int main (int argc, char *argv[]) {

char ch;

if(argc!=2) {

cou Подсчет: <имя файла>\п ;

return 1;

ifstream in(argv[l]);

cou Файл ввода открыть невоэможноХп ;

return 1;

Инициализация массива alpha [] -

inti;

for(i=0; i<26; i++) alpha [i] = 0;

ch = in. get () ;

if (isalpha(ch)) { если найдена буква, считаем ее ch = toupper(ch);

alpha [ch ]++; /A == 0,

B - A == 1, и т. д.

Вывод на экран результата for (i=0; 1<2б; 1+ + ) {

cout (char) СА + 1) : alpha [1] Xn;

in.closeO;

return 0;



608 Самоучитель С++

5а1. Копирование файла и смена регистра букв с контролем ошибок ttinclude <iostream> ttinclude <fstream> ttinclude <cctype>

using namespace

int main(int argc, char argv[])

char ch;

if(argc!=31 I

cou.--: Копование <откуда> <куда>\п ;

return 1;

if stream in (argv[l]) ;

ifCin) {

cou Фа ввода открыть невозможно\п ;

return

ofstreamout{argv[2]) ; if (tout) I

cout Файл открыть

return

while (lin.eof0 ) ( ,

1, .1 .Hal I

ch = in.get ( ) ; . ,

return 1

if (lin.eofO ) {

if (islower(ch)) ch = toupper(ch); eise ch = tolower(ch) ; out.put(ch);

return 1;

in.close 0;

out.close {) ; .> ..

if return

return 0;

5b. Подсчет букв с контролем ошибок ttinclude <iostrea.ii> ttinclude <fstream>



1 ... 197 198 199 [ 200 ] 201 202 203 ... 227

© 2006 - 2025 pmbk.ru. Генерация страницы: 0.081
При копировании материалов приветствуются ссылки.
Яндекс.Метрика