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

1 ... 188 189 190 [ 191 ] 192 193 194 ... 227


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

return 0;

3. fnnclvide <iostream>

using namespace std;

int maind

ios::fmtflags f;

flags 0 ; сохранение флагов ; т,

cout.unsetf(ios::dec);

cout.setf(ios:гshowbase ios::hex); *

cout 100 \n;

cout.flags(f); возврат флагов в исходное состояние

return

1. /* Создание .лицы натуральных и десятичных логарифмов чисел от 2 до 100

*/ ..... ..

tfinclude <iostreain>

#include <cmath>

using namespace std;

int main () {

double x;

cout. precis ion (5) ;

cou x Ig x In x\n\n ; . . . .

for(x 0; x <= 100.0; x++) {

cout.width(lO); i. .

cout x

cout.width (10); . c:

cout loglO(x) ; cout.width(10);

cout

return 0; ....



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

2. ttinclude <iostreain>

ttinclude <cstring>

using namespace std;

void centeE(char *s) ; -..J- : .1

center( Это здесь! );

.center( Мне нравится Ct+. ); - -

return

voi r(char *s) ., :. .

{ int len;

len = 40+ (strlen (s>/2) ;

cout.width(len) ; cou 3 \n }

tret

la. Таблица натуральных и десятичных логарифмов чисел от 2 до 100 linclude <iostream>

linclude <iomanip>

ftinclude

using namespace std;

int I

double x;

cout

cou x Ig x In x\n\n ;

for(x = 2.0; <= 100.0 +) I

cout x

cout

cout log(x)

return 0;

lb.ttinclude <iostream> ttinclude <iomanip>



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

ttinclude <cstring> ;

using namespace std;

void center(char *s);

t .

center( Это здесь! );

нравится

return 0;

void *s)

int len;

len =40 + (3trlen(s)/2);

cout setw(len) s

2. cou (ios:: showbase ex) 100;

3. Установка флага boolalpha для потока вывода приводит к тому, что значения булева типа выводятся на экран в виде слова trae или false. Установка флага boolalpha для потока ввода позволяет вводить значения булева типа с помощью слова trae или false.

1. ttinclude <iostream> #include <cstring> #include <cstdlib> using namespace std;

class strtype { ... char *p;

int len; -

public;

strtype(char *ptr); -strtype 0 (delete [] p; }

friend ostream & opera to r (ostream &stream, strtype &ob);

strtype: .-strtype (char *ptr) j : ,

len = strlen(ptr) + 1; . ; -



1 ... 188 189 190 [ 191 ] 192 193 194 ... 227

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