Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Multitude {
- private:
- string key;
- public:
- static const int size = 32;
- char *notice,*warning,*error,*action;
- char multitude[size+1];
- Multitude (){
- notice = "[~ Notice ] ";
- warning = "[? Warning] ";
- error = "[! Error ] ";
- action = "[$ Action ] ";
- }
- void Clear() {
- for (int i=0;i<size;i++) multitude[i]=NULL;
- }
- void ClearValue() {
- int id = 0;
- while (true) {
- cout<<action<<"Value to delete: ";
- getline(cin, key);
- // This code converts from string to number safely.
- stringstream myStream(key);
- if (myStream >> id)
- break;
- cout<<"Invalid number, please try again"<<endl;
- }
- multitude[id]=NULL;
- }
- int CountFilled () {
- int quant=0;
- for (int i=0;i<size;i++)
- if (multitude[i]) quant++;
- return quant;
- }
- void Show() {
- char *d;
- d = multitude;
- int w=8;
- char tmp;
- cout<<"\nTotal size: "<<sizeof(multitude)-1<<endl;
- cout<<"Filled cells: "<<CountFilled()<<endl;
- for (int i=0;i<(int)size-1;i++) {
- for (int j=0;j<w;j++,i++) {
- if (multitude[i]) tmp=multitude[i];
- else tmp=(char)(' ');
- printf("%5.0f: %c",(float)(i),tmp);
- //printf("%5.0f: %c",(float)(i),(char)multitude[i]);
- if (i>=size-1) break;
- *d++;
- }
- i--;
- cout<<endl;
- }
- }
- int GetValue() {
- int id = 0;
- while (true) {
- cout<<action<<"Numer to get: ";
- getline(cin, key);
- // This code converts from string to number safely.
- stringstream myStream(key);
- if (myStream >> id)
- break;
- cout<<"Invalid number, please try again"<<endl;
- }
- return id;
- }
- };
- class CharMultitude:public Multitude {
- public:
- CharMultitude() {
- Clear();
- }
- // Creates multitude from string
- void Create () {
- Clear();
- cout<<action<<"New string: ";
- string tempstr;
- getline(cin,tempstr);
- int i=0;
- while (tempstr[i]) {
- multitude[i] = tempstr[i];
- i++;
- }
- if (strlen(multitude)>size) cout<<warning<<"String is longer than "<<size<<" symbols and it will be cut off!";
- multitude[(int)strlen(multitude)]=NULL;
- }
- char Get(int n) {
- return multitude[n];
- }
- void Insert () {
- string newsymb;
- cout<<action<<"Insert symbol: ";
- getline(cin,newsymb);
- string key;
- int id = 0;
- while (true) {
- cout<<action<<"To position : ";
- getline(cin, key);
- // This code converts from string to number safely.
- stringstream myStream(key);
- if (myStream >> id)
- break;
- cout<<"Invalid number, please try again"<<endl;
- }
- multitude[id] = newsymb[0];
- }
- // Checks quantity of char in multitude
- int Check(char *elem) {
- int quant=0;
- char *p;
- p=multitude;
- while (*p) {
- if (strcmp(p,elem)==0) quant++;
- *p++;
- }
- return quant;
- }
- };
Add Comment
Please, Sign In to add comment