-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlec4_hw.cpp
More file actions
126 lines (110 loc) Β· 2.38 KB
/
lec4_hw.cpp
File metadata and controls
126 lines (110 loc) Β· 2.38 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include<iostream>
using namespace std;
//problem -1
// lower to upper
// void modifyString(char *str)
// {
// while(*str)
// {
// if(*str>='a' && *str<='z')
// {
// *str = *str -'a' +'A';
// }
// str++;
// }
// }
// // //problem - 2
// // reverse a string
// void reverseString ( char *str)
// {
// char *end = str;
// while(*end)
// {
// end++;
// }
// end--;
// while(str<end)
// {
// char temp = *str;
// *str = *end;
// *end = temp;
// str++ , end--;
// }
//
// //problem- 3
// void concatenateAndPrint(char *str1 ,const char *str2)
// {
// while(*str1)
// {
// str1++;
// }
// while((*str1 = *str2))
// {
// str1++ , str2++;
// }
// }
// //problem - 4
// void updateValues(int *a , int *b)
// {
// *a +=*b;
// *b = abs(*a - 2*(*b));
// }
// //problem - 5
// //function to swap two numbers
// void foo( int *i , int *j )
// {
// *i = *i + *j;
// *j = *i- *j;
// *i = *i - *j;
// }
//problem - 6
void countVowelsANDConsonants(const char*str ,int &vowels , int &consonants)
{
vowels = consonants = 0 ;
while(*str)
{
char ch = tolower(*str);
if(isalpha(ch)){
if(ch == 'a' || ch == 'e' ||ch == 'i' ||ch == 'o' ||ch == 'u' )
{
vowels++;
}
else{
consonants++;
}
}
str++;
}
}
int main()
{
// //problem -1
// // lower to upper
// char myString[] = "helloworld";
// modifyString(myString);
// cout<<myString;
// //problem - 2
// reverse a string
// char myString[] = "Programming";
// reverseString(myString);
// cout<<myString;
// //problem - 3
// char first[] = "Good";
// const char second[] = "Morning";
// concatenateAndPrint(first , second);
// cout<<first;
// //problem - 4
// int x = 5 , y = 3 ;
// updateValues(&x , &y);
// cout<<x<<" "<<y;
// // problem - 5
// int a = 4 , b = 5;
// foo(&a , &b);
// cout<<a<<" "<<b;
//problem - 6
const char *text = "Hello World";
int numsVowels , numConsonants;
countVowelsANDConsonants(text , numsVowels , numConsonants);
cout<<"Vowels:" <<numsVowels<<" Consonants: "<<numConsonants;
return 0 ;
}