Recall, a C-string is a null-terminated character array. The null characters pre
ID: 3698886 • Letter: R
Question
Recall, a C-string is a null-terminated character array. The null characters preceding the null terminator (') are considered to be the characters of the string. For example, the word "hello" would be stored in a char array of size six or bigger and the initial six characters would be 'h', 'e, . T o Any array elements after the null terminator are ignored. To get familiar with C-strings, write the following functions int getLength(const char w[l); // return the length of the c-string (excluding the null-terminator) void toUppercase (char w) II change any lowercase letters 'a' to 'z' to uppercase 'A' to '2* bool equal (const char v[], const char w[]); // return true if v and w contain the sane eharacters in same order, up to and including null terminators void copy (char destination const char sourcel): / copy source into destination including the null terminator. Assune the underying array tor destination is big enough to hold all the characters ot source. e.g.hlo"hello". I w only void removeLeadingSpaces (char II remove any leading spaces from contains spaces then a null terminator will be assigned to w char * getPointerToFirstNonSpace (const char w[]); // return a pointer to the first character that's not a space. o int countVowels (const char ) /1 return the number of vowels in w, where a vowel is 'a'','i', u(e're not counting 'y' as a vowel. bool comesBefore (const char v, const char wl) / return true if v comes before w in dictionary order. The neans compare character by character and return true or alse based on first nonmatching charaeter. I all character natch, return falsc.Explanation / Answer
here is your program : ------------>>>>>>>>>
#include<iostream>
using namespace std;
int getLength(const char w[]){
int i = 0;
while(w[i] != ''){
i++;
}
return i;
}
void toUpperCase(char w[]){
int i = 0;
while(w[i] != ''){
if((int)(w[i]) >= 97){
w[i] = (char)((int)w[i] - 32);
}
i++;
}
}
bool equal(const char w1[],const char w2[]){
int n = getLength(w1);
if(n != getLength(w2)){
return false;
}
for(int i = 0;i<n;i++){
if(w1[i] != w2[i]){
return false;
}
}
return true;
}
void copy(char dest[],const char w[]){
int i = 0;
while(w[i] != ''){
dest[i] = w[i];
i++;
}
dest[i] = w[i];
}
char* getPointerToFirstNonSpace(const char w[]){
int i = 0;
while(w[i] == ' '){
i++;
}
return (char*)(&w[i]);
}
void removeLeadingSpace(char w[]){
int i = 0,j,k;
while(w[i] == ' '){
i++;
}
for(j = i,k = 0;w[j] != '';j++){
w[k] = w[j];
k++;
}
w[k] = '';
}
int countVowels(const char w[]){
int i = 0;
int count = 0;
while(w[i] != ''){
switch(w[i]){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
count++;
}
}
return count;
}
bool comesBefore(const char v[],const char w[]){
int n1 = getLength(v);
int n2 = getLength(w);
if(n1 < n2){
for(int i = 0;i<n1;i++){
if(v[i] < w[i]){
return true;
}else if(v[i] > w[i]){
return false;
}
}
return true;
}else{
for(int i = 0;i<n2;i++){
if(v[i] < w[i]){
return true;
}else if(v[i] > w[i]){
return false;
}
}
return false;
}
}
int main(){
char w[] = " hello";
removeLeadingSpace(w);
cout<<w;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.