68 399
Assignments Done
Successfully Done
In December 2018

Answer to Question #50598 in C++ for Umer

Question #50598
Start with the String class from the NEWSTR example in this chapter. Add a member function called upit() that converts the string to all uppercase. You can use the toupper() library function, which takes a single character as an argument and returns a character that has been converted (if necessary) to uppercase. This function uses the
CCTYPE header file. Write some code in main() to test upit().
Expert's answer
#include <stdlib.h>
#include <iostream>  
#include <stdio.h>
#include <cstdlib> 
#include <cstring>
#include <cctype>
using namespace std;
class string has not been granted so I wrote my
class String  {
    char *pStr;
    int _size;
    String()  {
        pStr = NULL;
        _size = 0;
void Upit()
for (int i = 0; i < pStr[i]; i++)
pStr[i] = toupper(pStr[i]);
    String(char *str)  {
        _size = strlen(str) + 1;
        pStr = new char[_size];
        strcpy(pStr, str);
    int size()  {
        return _size;
    ~String()  {
        delete []pStr;
    friend ostream &operator; << (ostream &os;, String &obj;)  {
        for(int i = 0; i < obj.size(); i++)
            os <<obj.pStr[i];
        return os;
int main(){
String str("Blablabla");
    cout << str;
return 0;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions