jeudi 7 mai 2020

C++ star pattern generation and storage in Node

I am writing a program to generate and return one row at a time of the below pyramid, the main class passes the argument on the number of rows required and has linkedlist node to store each row in a separate node. every call should return 1 row, so that it can be stored in a single node, 2nd call should return the 2nd row of the pyramid and so on until the last row.

    X
   XXX
  XXXXX
 XXXXXXX
XXXXXXXXX 

here is my program

     class Pattern
     {
        private:
            typedef string svalue;
            svalue sstr, sstr_;
        public:                                     
           Pattern(int row =0) // <----number row passed by main program    
           {
               sstr=" ";
               sstr_="X";
               while (row > 0)
              {
                 sstr= sstr+sstr_; 
                 row--;
              }
           }

        svalue getdisc() const
        {
            return sstr;
         }
     };

my output

      X
      XX
      XXX

pls. suggest how to structure the loop

Aucun commentaire:

Enregistrer un commentaire