Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.44 KB | None | 0 0
  1. #include <iostream>          
  2. #include <string.h>
  3. #include <random>
  4. #include <time.h>
  5. using namespace std;
  6.  
  7. class foithths{
  8. private:
  9.     int size_name;
  10.     char *am;
  11.     string name;
  12.     unsigned int sem, pl_math;
  13.     float *pin;
  14. public:
  15.     //1
  16.     foithths(const char *a, string b){  //1
  17.         int i = strlen (a);     //am
  18.         am = new char [i+1];    //am
  19.         strcpy (am, a);         //am       
  20.         name = b;
  21.         sem = 1;
  22.         pl_math = 0;
  23.         pin = new float [1];
  24.         pin[0] = 0;                                 //για να μη βγαλει σκουπιδια σε περιπτωση εμφανισης του πινασκα
  25.     }
  26.    
  27.     foithths(const char *a, string b, unsigned int c){  //2
  28.         int i = strlen (a);     //am
  29.         am = new char [i+1];    //am
  30.         strcpy (am, a);         //am
  31.         name = b;
  32.         sem = c;
  33.         pl_math = 0;
  34.         pin = new float [1];
  35.         pin[0] = 0;                                 //για να μη βγαλει σκουπιδια σε περιπτωση εμφανισης του πινασκα
  36.     }
  37.  
  38.     foithths(const char *a, string b, unsigned int c, unsigned int d){  //3      
  39.         int i;
  40.         i = strlen (a);         //am
  41.         am = new char (i+1);    //am
  42.         strcpy (am, a);         //am
  43.         name = b;
  44.         sem = c;
  45.         pl_math = d;   
  46.         if (pl_math=!0){
  47.             pin = new float [pl_math];
  48.             srand((unsigned int)time(NULL));
  49.             float a = 5.0;
  50.             for (int i=0;i<pl_math;i++)
  51.                 cout << ((float(rand())/float((RAND_MAX)) * a)+5) << endl;
  52.             }          
  53.         }      
  54.        
  55.    
  56.        
  57.     foithths(const foithths &x){                                        //4 copy constractor
  58.     am = x.am;                     
  59.     name = x.name;
  60.     sem = x.sem;
  61.     pl_math = x.pl_math;   
  62.     }
  63.    
  64.     //2
  65.     void set_am(const char *a){
  66.         delete[]am;
  67.         int i = strlen (a);
  68.         am = new char (i+1);
  69.         strcpy (am, a);
  70.     }
  71.    
  72.     void set_name(string b){
  73.         name = b;
  74.     }
  75.    
  76.     void set_sem(unsigned int c){
  77.         sem = c;
  78.     }
  79.    
  80.     void set_pl_math(unsigned int d){
  81.         pl_math = d;
  82.     }
  83.    
  84.     void set_pin(float *e){
  85. /*      pin = new float [pl_math];
  86.         for (int i=0; i<pl_math; i++){
  87.             do{
  88.                 cin >> pin[i];
  89.             } while (!(pin[i]>=5 & pin[i]<=10));
  90.         }
  91.        
  92.         if (pl_math=!0){
  93.             pin = new float [pl_math];
  94.             for (int i=0; i<pl_math; i++){
  95.                 do{
  96.                     pin[i] = e[i];
  97.                 } while (!(pin[i]>=5 & pin[i]<=10));
  98.             }          
  99.         }   */ 
  100.         if (pl_math=!0){
  101.             pin = new float [pl_math];
  102.             srand((unsigned int)time(NULL));
  103.             float a = 5.0;
  104.             for (int i=0;i<pl_math;i++)
  105.                 cout << ((float(rand())/float((RAND_MAX)) * a)+5) << endl;         
  106.         }      
  107.     }
  108.  
  109.  
  110.     char get_am(){
  111.         return *am;
  112.     }
  113.  
  114.     string get_name(){ 
  115.         return name;   
  116.     }
  117.    
  118.     unsigned int get_sem(){
  119.         return sem;
  120.     }
  121.    
  122.     unsigned int get_pl_math(){
  123.         return pl_math;
  124.     }
  125.    
  126.     float *get_pin(){
  127. //      int j;
  128. //      for (j=0; j<pl_math; j++){
  129. //          cout << pin[j] << endl;
  130. //      }
  131.         return pin;
  132.     }
  133.    
  134.     //3
  135.    
  136.     void prosthiki_math(foithths &x){                                                                           //να αλλαξω το ωοιδ
  137.         pl_math++;
  138.         float* pin2 = new float [pl_math];
  139.         for (int j=0; j<pl_math-1; j++){
  140.             pin2[j] = pin[j];
  141.         }  
  142.         do{
  143.             cin >> pin2[pl_math];
  144.         } while (!(pin2[pl_math]>=5 & pin2[pl_math]<=10));
  145.         delete(pin);
  146.         pin = new float [pl_math];
  147.         for (int i=0; i<pl_math; i++){
  148.             do{
  149.                 pin[i] = pin2[i];
  150.             } while (!(pin[i]>=5 & pin[i]<=10));
  151.         }  
  152.  
  153.     }
  154.    
  155.    
  156.    
  157.    
  158.    
  159.    
  160.    
  161. //  ~foithths();
  162. };
  163.  
  164. /*  float readp(unsigned int pl_m){
  165.         float *p = new float [pl_m];
  166.         for (int i=0; i<pl_m; i++){
  167.             do{
  168.                 cin >> p[i];
  169.             }while (!(p[i]>=5 && p[i]<=10));
  170.         }
  171.         return *p;
  172.     }*/
  173.  
  174. int main(void){
  175.  
  176.    
  177. //  foithths x1("1" , "A" );
  178. //  foithths x2("2" , "B" , 2);
  179.     unsigned int d = 2;
  180.     foithths x3("345" , "Cat" , 3, 1);
  181. //  foithths x4(x3);
  182.    
  183. //  cout << x3.get_am() <<endl;                                            
  184. //  cout << x3.get_name() <<endl;                                              
  185. //  cout << x3.get_sem() <<endl;                                                     
  186. //  cout << x3.get_pl_math() <<endl;                                                   
  187.     cout << x3.get_pin() <<endl;                                                           
  188.     cout << endl;
  189. /*  x2.get_am();                                                       
  190.     x2.get_name();                                                     
  191.     x2.get_sem();                                                      
  192.     x2.get_pl_math();                                                  
  193.     x2.get_pin();  
  194.     cout << endl;
  195.     x3.get_am();                                                       
  196.     x3.get_name();                                                     
  197.     x3.get_sem();                                                      
  198.     x3.get_pl_math();                                                  
  199.     x3.get_pin();
  200.    
  201.     x3.set_am("000");                                                      
  202.     x3.set_name("AAA");                                                    
  203.     x3.set_sem(9);                                                     
  204.     x3.set_pl_math(2);                                                 
  205.     x3.set_pin();          
  206.    
  207.     x3.get_am();                                                       
  208.     x3.get_name();                                                 
  209.     x3.get_sem();                                          
  210.     x3.get_pl_math();                                  
  211.     x3.get_pin();                                              
  212.     cout << endl;*/
  213. }
  214.  
  215.  
  216.  
  217. //TO DO
  218. //SETTER am EMFANIZEI MONO TO 1 GRAMMA, ΕΡΩΤΗΜΑ 3 ΑΛΛΑΖΩ ΤΟ VOID ΚΑΙ ΒΛΕΠΩ ΑΝ ΔΟΥΛΕΥΕΙ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement