Needs to be written in C++ just simple corrections and code snipets A).Look at t
ID: 3683362 • Letter: N
Question
Needs to be written in C++ just simple corrections and code snipets
A).Look at the following code. What value will be stored in s after the code is executed?
char name[10];
int s;
strcpy(name, “Jimmy”);
s = strlen(name);
B).What header file must be included in the program using string functions such as strlen( ) and strcpy( )?
C). What header file must be included in a program using string objects?
D). Assume input is a char array holding a C-string. Write code that counts the number of elements in the array that contain an alphabetic character.
E). Correct the following code:
char str[ ] = “Stop”;
if (isupper(str) == “STOP”)
exit(0);
Explanation / Answer
1. value of s = length of string "Jimmy" = 5
2. In C++, 'cstring' is header file - #include<cstring>
3. #include<string> : 'string' header file
4.
#include<iostream>
using namespace std;
int main(){
//let name is C-string
char name[10];
int i=0;
while(name[i] != '')
i++;
cout<<"Size: "<<i<<endl;
return 0;
}
5.
char str[ ] = "Stop";
if (strlen(str) == 4 && isupper(str[0]) == 'S' && isupper(str[1]) == 'T' && isupper(str[2]) == 'O' && isupper(str[3]) == 'P')
exit(0);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.