*/
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
void init_random()
{
srand(time(NULL));
}
bool is_digit_two(int x)
{
if(x%2==0)
return true;
else
return false;
}
bool no_digit_two(int x)
{
if(!is_digit_two(x))
return true;
else
return false;
}
bool is_first(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+1;i++)
if(x%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
char upper_letter[26];
char lower_letter[26];
void init_letter()
{
char a;
int i;
for(a='A',i=0;a<'Z'+1;a++,i++)
upper_letter[i]=a;
for(a='a',i=0;a<'z'+1;a++,i++)
lower_letter[i]=a;
}
char give_letter_upper()
{
int i;
i=rand()%26;
return lower_letter[i];
}
char give_upper_letter()
{
int i;
i=rand()%26;
return upper_letter[i];
}
char random_letter()
{
int i;
i=rand()%2;
if(i==0)
return give_letter_upper();
else
return give_upper_letter();
}
void write_first_number_letter()
{
int i,j,k,l;
do
{
k=rand()%13+1;
}while(!is_first(k));
i=0;
j=1;
cout<<endl;
cout<<k<<" first numbers :\n";
do
{
++j;
if(is_first(j))
{
cout<<j<<endl;
for(l=0;l<j+1;l++)
{
cout<<random_letter();
}
++i;
cout<<endl;
}
}while(i<k);
}
class My_letters
{
private:
char my_tekst[26];
public:
My_letters(char tekst[26])
{
strcpy(my_tekst,tekst);
}
bool is_upper(char x)
{
int i,sum;
sum=0;
for(i=0;i<26;i++)
if(x==upper_letter[i])
{
++sum;
}
if(sum==1)
return true;
else
return false;
}
bool is_lower(char x)
{
int i,sum;
sum=0;
for(i=0;i<26;i++)
if(x==lower_letter[i])
{
++sum;
}
if(sum==1)
return true;
else
return false;
}
void write_text()
{
cout<<my_tekst<<endl;
}
void write2_text()
{
char temp_text[26],c;
int i,j;
for(i=0;i<26;i++)
{
if(is_upper(my_tekst[i]))
{
for(j=0,c='A';c<my_tekst[i]+1;c++,++j)
{
;
}
temp_text[i]=lower_letter[j-1];
}
else
temp_text[i]=upper_letter[j];
if(is_lower(my_tekst[i]))
{
for(j=0,c='a';c<my_tekst[i]+1;c++,++j)
{
;
}
temp_text[i]=upper_letter[j];
}
else
temp_text[i]=lower_letter[j-1];
}
cout<<temp_text<<endl;
}
};
int main(int argc, char **argv)
{
int i,j,k;
init_random();
init_letter();
for(i=0;i<26;i++)
cout<<upper_letter[i]<<" ";
cout<<endl;
for(j=0;j<26;j++)
cout<<lower_letter[j]<<" ";
cout<<endl;
for(i=0;i<27;i++)
{
if(is_digit_two(i+1))
cout<<upper_letter[i-1];
else
cout<<lower_letter[i-1];
}
cout<<endl;
for(j=0;j<27;j++)
{
if(no_digit_two(j+1))
cout<<upper_letter[j-1];
else
cout<<lower_letter[j-1];
}
cout<<endl;
write_first_number_letter();
cout<<endl;
cout<<endl;
char *test_text;
test_text=new char[26];
for(i=0;i<26;i++)
test_text[i]=random_letter();
My_letters My_l(test_text);
My_l.write_text();
My_l.write2_text();
delete test_text;
return 0;
}
Brak komentarzy:
Prześlij komentarz