question4_merged.pdf
- 1. 1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 char str[100];
8 int count=0;
9 cout<<"enter the string"<<endl;
10 cin.getline(str,100);
11 for(int i=0;str[i]!='0';i++)
12 {
13 count++;
14 }
15 cout<<"the length of the string is :"<<count;
16 return 0;
17 }
18
- 2. 1 #include <iostream>
2 using namespace std;
3 int main()
4 {
5 string str;
6 int count=0;
7 cout<<"enter the string"<<endl;
8 getline(cin,str);
9 for(int i=0;str[i]!='0';i++)
10 {
11 count++;
12 }
13 cout<<"the length of the string is:"<<count<<endl;
14 return 0;
15 }
16
- 3. 1 //using string object
2 #include <iostream>
3 using namespace std;
4
5 int main()
6 {
7 string line;
8 int vowels, consonants, digits, spaces;
9
10 vowels = consonants = digits = spaces = 0;
11
12 cout << "Enter a line of string: ";
13 getline(cin, line);
14
15 for(int i = 0; i < line.length(); ++i)
16 {
17 if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
18 line[i]=='o' || line[i]=='u' || line[i]=='A' ||
19 line[i]=='E' || line[i]=='I' || line[i]=='O' ||
20 line[i]=='U')
21 {
22 ++vowels;
23 }
24 else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
25 {
26 ++consonants;
27 }
28 else if(line[i]>='0' && line[i]<='9')
29 {
30 ++digits;
31 }
32 else if (line[i]==' ')
33 {
34 ++spaces;
35 }
36 }
37
38 cout << "Vowels: " << vowels << endl;
39 cout << "Consonants: " << consonants << endl;
40 cout << "Digits: " << digits << endl;
41 cout << "White spaces: " << spaces << endl;
42
43 return 0;
44 }
45
- 4. 1 //using string object
2 #include <iostream>
3 using namespace std;
4
5 int main()
6 {
7 string line;
8 int vowels, consonants, digits, spaces;
9
10 vowels = consonants = digits = spaces = 0;
11
12 cout << "Enter a line of string: ";
13 getline(cin, line);
14
15 for(int i = 0; i < line.length(); ++i)
16 {
17 if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
18 line[i]=='o' || line[i]=='u' || line[i]=='A' ||
19 line[i]=='E' || line[i]=='I' || line[i]=='O' ||
20 line[i]=='U')
21 {
22 ++vowels;
23 }
24 else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
25 {
26 ++consonants;
27 }
28 else if(line[i]>='0' && line[i]<='9')
29 {
30 ++digits;
31 }
32 else if (line[i]==' ')
33 {
34 ++spaces;
35 }
36 }
37
38 cout << "Vowels: " << vowels << endl;
39 cout << "Consonants: " << consonants << endl;
40 cout << "Digits: " << digits << endl;
41 cout << "White spaces: " << spaces << endl;
42
43 return 0;
44 }
45
- 5. 1 //using string object
2 #include <iostream>
3 using namespace std;
4
5 int main()
6 {
7 string line;
8 int vowels, consonants, digits, spaces;
9
10 vowels = consonants = digits = spaces = 0;
11
12 cout << "Enter a line of string: ";
13 getline(cin, line);
14
15 for(int i = 0; i < line.length(); ++i)
16 {
17 if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
18 line[i]=='o' || line[i]=='u' || line[i]=='A' ||
19 line[i]=='E' || line[i]=='I' || line[i]=='O' ||
20 line[i]=='U')
21 {
22 ++vowels;
23 }
24 else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
25 {
26 ++consonants;
27 }
28 else if(line[i]>='0' && line[i]<='9')
29 {
30 ++digits;
31 }
32 else if (line[i]==' ')
33 {
34 ++spaces;
35 }
36 }
37
38 cout << "Vowels: " << vowels << endl;
39 cout << "Consonants: " << consonants << endl;
40 cout << "Digits: " << digits << endl;
41 cout << "White spaces: " << spaces << endl;
42
43 return 0;
44 }
45
- 6. 1 //using string object
2 #include <iostream>
3 using namespace std;
4
5 int main()
6 {
7 string line;
8 int vowels, consonants, digits, spaces;
9
10 vowels = consonants = digits = spaces = 0;
11
12 cout << "Enter a line of string: ";
13 getline(cin, line);
14
15 for(int i = 0; i < line.length(); ++i)
16 {
17 if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
18 line[i]=='o' || line[i]=='u' || line[i]=='A' ||
19 line[i]=='E' || line[i]=='I' || line[i]=='O' ||
20 line[i]=='U')
21 {
22 ++vowels;
23 }
24 else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
25 {
26 ++consonants;
27 }
28 else if(line[i]>='0' && line[i]<='9')
29 {
30 ++digits;
31 }
32 else if (line[i]==' ')
33 {
34 ++spaces;
35 }
36 }
37
38 cout << "Vowels: " << vowels << endl;
39 cout << "Consonants: " << consonants << endl;
40 cout << "Digits: " << digits << endl;
41 cout << "White spaces: " << spaces << endl;
42
43 return 0;
44 }
45
- 7. 1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 string str;
8 cout<<"Enter the string :"<<endl;
9 getline(cin,str);
10 for(int i=0;str[i]!='0';i++)
11 {
12 if (str[i] >= 'a' && str[i] <= 'z') //checking for lowercase characters
13 str[i] = str[i] - 32; //converting lowercase to uppercase
14 }
15 cout<<"n The string in upper case: "<< str;
16
17 return 0;
18 }
19
- 8. 1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 string str;
8 cout<<"Enter the string :"<<endl;
9 getline(cin,str);
10 for(int i=0;str[i]!='0';i++)
11 {
12 if (str[i] >= 'A' && str[i] <= 'Z') //checking for uppercase characters
13 str[i] = str[i] + 32; //converting uppercase to lowercase
14 }
15 cout<<"n The string in lower case: "<< str;
16
17 return 0;
18 }
19
- 9. 1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 char str1[100];
8 char str2[100];
9 cout<<"enter the string of str2:"<<endl;
10 cin.getline(str2,100);
11 int i=0,j=0;
12 while(str2[i]!='0')
13 {
14 str1[j] = str2[i];
15 j++;
16 i++;
17 }
18 str1[i]='0';
19 cout<<"string str2:"<<str2<<endl;
20 cout<<"string str1:"<<str1<<endl;
21 return 0;
22 }
23
- 10. 1 #include <iostream>
2
3 using namespace std;
4
5 int main()
6 {
7 char str1[100];
8 char str2[100];
9 cout<<"enter the string of str2:"<<endl;
10 cin.getline(str2,100);
11 int i=0,j=0;
12 while(str2[i]!='0')
13 {
14 str1[j] = str2[i];
15 j++;
16 i++;
17 }
18 str1[i]='0';
19 cout<<"string str2:"<<str2<<endl;
20 cout<<"string str1:"<<str1<<endl;
21 return 0;
22 }
23