Добавил:
Помощь с лабораторными, контрольными практическими и курсовыми работами по: - Инженерной и компьютерной графике - Прикладной механике Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
0
Добавлен:
08.08.2022
Размер:
1.56 Кб
Скачать
#include <cstdlib>
#include <conio.h>
#include <iostream>
#include <string>
#include <bits/stdc++.h>
using namespace std;

#define MAX 79

class Stroka
{
private:
	string s;
	int len;
public:
	
	Stroka()
	{
		s = "adf gth 6";
		cout<<"you create line:"<<endl;
		cout<<s<<endl;
		cout<<"length of line:"<<endl;
		len = s.length();
		cout<<len<<endl;
	}
	int Set();
	
	void print();
	const char* Run();
	
	string operator = ( const string &str);
	
	

};

int Stroka::Set()
{
		cout<<"line:"<<endl;
		getline(cin, s);
		len = s.length();
		if( len > MAX)
		{
			s.resize(MAX);
		}
		cout<<"new line:"<<endl;
		cout<<s<<endl;
		cout<<"length of line:"<<endl;
		cout<<len<<endl;
	}


void Stroka::print()
{
	cout<<s<<endl;
}

string Stroka::operator = (const string &str)
{
	int len2 = str.length(), i, n;
	if(len2 >= len)
	n = len;
	else
	n = len2;
	for(i=0; i < n; i++)
	{
		s[i] = str[i];
	}
	s[n] = '\0';
	
	
}

const char* Stroka::Run()
{
	if( len > 5 && len < 30)
	{
		
		for(int i=0; i < len; i++)
	    {
		    if(s[i] <= 'Z' && s[i] >= 'A') 
			{
                s[i] += 32;
            } 
            if(s[i] >= 'a' && s[i] <= 'z') 
			{
                s[i] -= 32;
            }
	    }
	    const char* p = s.c_str();
		return p;
	}
	else
	return "length >= 30 or <= 5";
}

	

int main()
{
	Stroka S1;
	S1.Set();

	Stroka S2;
	S2 = S1;
	cout<<S2.Run()<<endl;
	cout<<"check function =:"<<endl;
	cout<<"S2"<<endl;
	S2.print();
	return 1;
	
}
Соседние файлы в папке ЛР 4