-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlancuchy.cpp
More file actions
107 lines (82 loc) · 2.52 KB
/
lancuchy.cpp
File metadata and controls
107 lines (82 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
char napis[20] = "Ala ma kota";
cout << napis << "\n";
//spowoduje blad:
//napis="kot";
//cout << napis<<"\n";
//nie spowoduje bledu:
char *napis2 = (char *) "Ala ma kota";
cout << napis2 << "\n";
napis2 = (char *) "Inny napis";
cout << napis2 << "\n";
//pokaz konkretny znak:
cout << napis[0] << "\n";
//sprawdz plec uzytkownika:
string imie;
cout << "Podaj imie: ";
cin >> imie;
unsigned long dlugosc_imienia = imie.length ();
cout << "Dlugosc: " << dlugosc_imienia << "\n";
if (imie[dlugosc_imienia - 1] == 'a')
cout << "Wydaje mi sie, ze jestes kobieta" << "\n";
else
cout << "Wydaje mi sie, ze jestes facetem" << "\n";
//odwracanie wyrazow:
string wyraz;
cout << "Podaj wyraz do odwrocenia (bez spacji): ";
cin >> wyraz;
int dlugosc = (int) (wyraz.length () - 1);
for (int i = dlugosc; i >= 0; i--)
{
cout << wyraz[i];
}
//uzycie getline - zapis ze spacjami:
string napis3;
cout << "\n" << "Podaj wyraz ze spacjami: ";
cin.ignore (); //"wyczysc" strumien
getline (cin, napis3);
cout << napis3 << "\n";
//wyznacz dlugosc napisu i wyswietl na ekranie:
unsigned long dlugosc2 = napis3.length ();
cout << dlugosc2 << "\n";
// laczenie dwoch stringow:
string jeden = "Ala ma";
string dwa = " kota";
string trzy = jeden + dwa;
cout << trzy << "\n";
//Zmiana wielkosci liter:
string napis4 = "Ala ma kota";
transform (napis4.begin (), napis4.end (), napis4.begin (), ::tolower);
cout << napis4 << "\n";
transform (napis4.begin (), napis4.end (), napis4.begin (), ::toupper);
cout << napis4 << "\n";
//Znajdz fraze:
string napis5 = "Ala ma kota";
string szukaj = "kot";
size_t pozycja = napis5.find (szukaj);
if (pozycja != string::npos)
cout << "znaleziono na pozycji: " << pozycja << "\n";
else
cout << "nie znaleziono" << "\n";
//Wykasuj czesc lancucha:
string napis6 = "Ala ma kota";
napis6.erase (3, 3);
cout << napis6 << "\n";
//Zastap czesc lancucha:
string napis7 = "Ala ma kota";
napis7.replace (4, 2, "nie ma");
cout << napis7 << "\n";
//Wstaw do lancucha:
string napis8 = "Ala ma kota";
napis8.insert (11, " Filemona");
cout << napis8 << "\n";
//Wyciagnij czesc napisu do nowego lancucha:
string napis9 = "Ala ma kota";
string nowynapis = napis9.substr (4, 7);
cout << nowynapis;
return 0;
}