Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "stdafx.h"
- #include <stdio.h>
- #include <iostream>
- #include <conio.h>
- #include <string.h>
- #include <fstream>
- #define SIZE 255
- using namespace std;
- class String
- {
- char* str1;
- char* str2;
- public:
- String();
- ~String();
- char operator = (char*);
- void print();
- void set (char*);
- char* run();
- };
- String::String()
- {
- str1 = new char[SIZE];
- str1[0] = '\0';
- str2 = new char[SIZE];
- str2[0] = '\0';
- }
- String::~String()
- {
- delete[] str1;
- delete[] str2;
- }
- char* String::run()
- {
- unsigned int i;
- unsigned int j =0;
- if (fmod(strlen(str1),3.0)==0.0)
- {
- for (i=0; i<strlen(str1);)
- {
- if (fmod(str1[i],3.0)==0.0)
- {
- i++;
- }
- else
- {
- str2[j] = str1[i];
- i++;
- j++;
- }
- }
- str2[j] = '\0';
- }
- else
- {
- strcpy(str2,str1);
- }
- return str2;
- };
- char String::operator = (char* str1)
- {
- strcpy(str2,str1);
- return *str2;
- }
- void String::set(char *inStr)
- {
- unsigned int i;
- for (i=0; i<strlen(inStr); i++)
- {
- str1[i] = inStr[i];
- }
- str1[i] = '\0';
- };
- void String::print()
- {
- cout<<str1<<endl;
- cout<<str2<<endl;
- }
- void main()
- {
- char inStr[256], newStr[256];
- cout<<"Input string: "<<endl;
- cin.getline(inStr, 256);
- String str;
- cout<<endl<<"Source & converted strings:"<<endl;
- str.set(inStr);
- ofstream file("text.txt",ios::out);
- file<<"sourse string: "<<inStr<<"\n"<<"converted string: "<<str.run()<<"\n";
- file.close();
- str.print();
- String *s1, *s2;
- s1 = new String();
- s2 = new String();
- s2->set(inStr);
- s1=s2;
- cout<<endl<<"String, copied using the overloading:"<<endl;
- s1->print();
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement