I\'m not grasping C++ and the semester is almost over with only two assignments
ID: 3687417 • Letter: I
Question
I'm not grasping C++ and the semester is almost over with only two assignments left. My instructor assigned the following: Put the following characters into a text file using Notepad or any file editor. A a 9 space ! A total of five characters including the space. Read the file one character at a time. Use character functions to print out the type of character each character is. Note for a 9, it is both numeric and alphanumeric. Use functions for alphabetic , lower, upper, alphanumeric, numeric, digit, punctuation, or a space. Put "Calhoun College" into a string variable. Print the string the following ways using a loop and functions: all upper case all lower case title case-You will need to look for a space and then capitalize the next character. backwards Print the length of the string. Append 10 "z"'s to the end of the string using a function and print. Insert "Community" between "Calhoun" and "College" using a function. Keep appropriate spacing. Print the new string. I honestly don't even know where to begin. Any help would be appreciated.Explanation / Answer
Read the file one character at a time. Use character functions to print out the type of character each character is
#include <stdio.h>
main()
{ char ch /* declaration for a character object ch */
int flag /* flag stores the number of items read by scanf() */
cout<<"***Copy Program*** "
cout<<"Type text, terminate with EOF ")
flag =cin<<"%c", &ch /* read the first char */
while (flag != EOF) { /* repeat while not EOF */
cout<<"%c", ch /* print the last char read */
flag = cin<<"%c", &ch /* read the next char, update flag */
} /* flag is EOF, ch may be unchanged */
}
Here is a code fragment that checks whether a character is a lower case letter, an upper case letter, a digit, etc.
#include <stdio.h>
int print_reps( char ch )
main()
{ char ch int flag
Cout<<"***Character Attributes*** "
Cout<<"Type text, terminate with EOF "
flag = cin<<"%c", &ch /* read the first char */
while (flag != EOF) {
if (ch >= 'a' && ch <= 'z') { /* lower case letter? */
print_reps(ch)
cout<<"lower case letter "
}
else if (ch >= 'A' && ch <= 'Z') { /* upper case letter? */
print_reps(ch)
cout<<"an upper case letter "
}
else if (ch >= '0' && ch <= '9') { /* digit character? */
print_reps(ch)
cout<<"a digit symbol "
}
else if (ch == '.' || ch == ',' || ch == '' || ch == ':' ||
ch == '?' || ch == '!') { /* punctuation? */
print_reps(ch)
cout<<"a punctuation symbol "
}
else if (ch == ' ') { /* space? */
print_reps(ch)
cout<<"a space character "
}
else if (ch < 32 || ch == 127) { /* control character? */
print_reps(ch)
cout<<"a control character "
}
else { /* must be a special symbol */
print_reps(ch)
printf("a special symbol ")
}
flag = cin<<"%c", &ch /* read the next char */
} /* end of while loop */
} /* end of program */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.