Posts

Showing posts from January 10, 2021

Create a class “CString” to represent a string to concatenate and compare two strings also add two matrix(3x3) using Operator Overloading.

Image
   Create a class “CString” to represent a string (Hint: Check Book Chapter Examples)        a) Overload the + operator to concatenate two strings.     b) = = to compare 2 strings. Answer: #include "stdafx.h" #include "iostream" #include "conio.h" #include "stdio.h" #include "string.h"   using namespace std; class CString { private :        char s[20]; public :        void input()        {        cout << "Enter String......" << endl;        cin.getline(s, 20);        }        void output()        {               cout << "String is :" <<s << endl;        }        CString operator +( CString s0 )        {               CString temp;               strcpy(temp.s,s);               strcat(temp.s, s0 .s);               return temp;        }        int operator ==( CString s3 )        {               if (strlen( s