-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertSmallToCapital.cpp
More file actions
96 lines (79 loc) · 1.99 KB
/
Copy pathconvertSmallToCapital.cpp
File metadata and controls
96 lines (79 loc) · 1.99 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
/*
// convert only a single charater into Upper Case
#include<iostream>
using namespace std;
char convert(char name){
char answer = name - 'a' + 'A';
return answer;
}
int main(){
char name;
cout << "Enter a lowercase character: ";
cin >> name;
cout << convert(name) << endl;
return 0;
}
// Convert a sentence or whole paragraphs into Upper Case
#include <iostream>
#include <string>
using namespace std;
int main(){
string paragraph;
cout << "Enter a paragraph: ";
getline(cin, paragraph);
for (int i = 0; i < paragraph.length(); i++){
if (paragraph[i] >= 'a' && paragraph[i] <= 'z')
paragraph[i] = paragraph[i] - 'a' + 'A';
}
cout << "\nConverted Paragraph:\n"
<< paragraph << endl;
return 0;
}
// Using Function to convert a sentence or whole paragraphs into Upper Case
#include <iostream>
#include <string>
using namespace std;
string convertToUppercase(string text)
{
for (int i = 0; i < text.length(); i++)
{
if (text[i] >= 'a' && text[i] <= 'z')
{
text[i] = text[i] - 'a' + 'A';
}
}
return text;
}
int main(){
string paragraph;
cout << "Enter a paragraph: ";
getline(cin, paragraph);
string uppercaseParagraph = convertToUppercase(paragraph);
cout << "\nConverted Paragraph:\n"
<< uppercaseParagraph << endl;
return 0;
}
*/
// Alternative (Using toupper) to convet
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
string convertToUppercase(string text)
{
for (int i = 0; i < text.length(); i++)
{
text[i] = toupper(text[i]);
}
return text;
}
int main()
{
string paragraph;
cout << "Enter a paragraph: ";
getline(cin, paragraph);
string uppercaseParagraph = convertToUppercase(paragraph);
cout << "\nConverted Paragraph:\n"
<< uppercaseParagraph << endl;
return 0;
}