-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings_ex_1.cpp
executable file
·134 lines (108 loc) · 2.52 KB
/
strings_ex_1.cpp
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <math.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
using namespace std;
void primaFunzione()
{
string prima = "Ciao, ";
string seconda = "mondo.";
string unica = prima + seconda;
cout << prima << seconda << endl;
cout << unica << endl;
}
void secondaFunzione()
{
string frutta = "Pesca";
char lettera1 = frutta[0];
char lettera2 = frutta[1];
cout << frutta << endl;
cout << lettera1 << endl;
cout << lettera2 << endl;
}
void terzaFunzione()
{
int lunghezza;
char ultimoCarattere;
string frutta = "Pesca";
lunghezza = frutta.length();
ultimoCarattere = frutta[lunghezza-1];
cout << lunghezza << endl;
cout << ultimoCarattere << endl;
}
void quartaFunzione()
{
int lunghezza;
string frutta = "Ananas";
lunghezza = frutta.length();
int contatore = 0;
while (contatore < lunghezza)
{
char lettera = frutta[contatore];
cout << lettera << endl;
contatore = contatore + 1;
}
}
void quintaFunzione()
{
string frutta = "Pesca";
int primo_indice_s = frutta.find('s');
int primo_indice_a = frutta.find('a');
cout << primo_indice_s << endl;
cout << primo_indice_a << endl;
}
void sestaFunzione()
{
string frutta1 = "Pesca";
string frutta2 = "Pesca";
if (frutta1==frutta2)
cout << "Stringhe UGUALI" << endl;
else
cout << "Stringhe DIVERSE" << endl;
if (frutta1.compare(frutta2) == 0)
cout << "Stringhe UGUALI" << endl;
else
cout << "Stringhe DIVERSE" << endl;
}
void settimaFunzione()
{
string frutta1 = "Matematica";
string stringaNuova = frutta1.substr(2,4);
cout << stringaNuova << endl;
string stringaNuova2 = frutta1.substr(2);
cout << stringaNuova2 << endl;
}
void ottavaFunzione()
{
string frutta1 = "Matematica";
frutta1.replace(4,2,"XX");
cout << frutta1 << endl;
}
void nonaFunzione()
{
string frutta1 = "matematica";
int index = 0;
while (index < frutta1.length())
{
frutta1[index] = toupper(frutta1[index]);
index++;
}
cout << frutta1 << endl;
}
void decimaFunzione()
{
string frutta1 = "MATEMATICA";
int index = 0;
while (index < frutta1.length())
{
frutta1[index] = tolower(frutta1[index]);
index++;
}
cout << frutta1 << endl;
}
int main()
{
decimaFunzione();
system("pause");
}