Passing Arrays in a Class not working

Hello

Please help i am trying to collect information from a function through an array variable of the class type. I need help in doing this, thank you for your help.

regards

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
  //Write a main program that does the following:
//• Declare an array to hold information for the DVDs available in the GreatClassics DVD store.
// The elements of the array must be of type DVD.
//• You must have member variables to hold the title of a DVD,
//the name of the director, the year released, number of copies in stock, the running time in minutes, etc.
//Initialise the array with applicable information.


#include <iostream>
#include <string>

using namespace std;
class  dvd
{

  private:
  string dvdTitle, dName, memberFirstName, memberLastName, memberEmailaddress, memberStreetAddress, memberSuburb, memberTown, memberCity, zipCode;
  int totalDiscounted, yearReleased, before1960, under120, membID, runningTime, NoOfCopiesAvailable, rentalPeriod, mobileNo, dvdNo ;
  double price, discount ;
  public:

 void clearValues()
 {

   //dvdTitle = " ", ;
   totalDiscounted = 0, before1960 = 0, under120 = 0 ;


 }

  string getTitle( string &dvdTitle)
  {
      cout<<"Enter dvd title :";
      getline(cin,dvdTitle);
      cout<<endl;
      return dvdTitle;
  }

  int getRunningTime( int &runningTime )
  {
      cout<<"Enter running time  : ";
      cin>>runningTime;
      cout<<endl;
      if( runningTime < 120 )
      {
          under120++;

      }
      else
      {
          under120 = under120;
      }
      return under120;
  }

  int getYearReleased(int &yearReleased )
  {
      cout<<"Enter year of release : ";
      cin>>yearReleased;
      cout<<endl;
      if (yearReleased < 1960)
      {
          before1960++;
      }
      else
      {
          before1960 = before1960;

      }
      return before1960;
  }

  string getDirectorName( string &dName)
  {
      cout<<"Enter Director Name : ";
      cin>>dName;
      //getline(cin, directorName);
      cout<<endl;
      return dName;
  }
    int dvdCopiesAvailable( int &NoOfCopiesAvailable)
    {
      cout<<"Enter No of Copies Available ";
      cin>>NoOfCopiesAvailable;
      cout<<endl;
      return NoOfCopiesAvailable;
    }

  void getDvDNo( string &dvdTitle, int &dvdNo )
  {
      cout<<"Enter dvd title  :";
      getline(cin,dvdTitle);
      cout<<endl;

      cout<<"Enter dvd title No";
      cin>>dvdNo;
      cout<<endl;



    }

  void getMemberInfo( int &membID, string &memberLastName, string &memberFirstName, string &memberEmailaddress, string &memberStreetAddress, string &memberSuburb, string &memberTown, string &memberCity, string &mobileNo  )
  {
    //mID = (srand()-1)*5;
      cout<<"Enter member ID :";
      cin>>membID;
      cout<<endl;

      cout<<" Enter Member Last Name ";
      cin>>memberLastName;
      cout<<endl;

      cout<<" Enter Member First Name ";
      cin>>memberFirstName;
      cout<<endl;

      cout<<" Enter Member Email Address";
      cin>>memberEmailaddress;
      cout<<endl;

      cout<<" Enter Member Street Address";
      cin>>memberStreetAddress;
      cout<<endl;

      cout<<" Enter Member suburb";
      cin>>memberSuburb;
      cout<<endl;

      cout<<" Enter Member Town";
      cin>>memberTown;
      cout<<endl;

      cout<<" Enter Member City";
      cin>>memberCity;
      cout<<endl;

      cout<<" Enter Member Mobile Number";
      cin>>mobileNo;
      cout<<endl;

        }

  void rentOut( int &mID, int &dvdNo ,int &rentalPeriod)
  {
     // if (NoOfCopiesAvailable == 0)
      //{
      //    cout<<"dvd Out of Stock";
      //    cout<<endl;
      //}
      //else
      //{
         cout<<"Enter Member ID : ";
         cin>>mID;
         cout<<endl;

         cout<<"Enter Dvd No : ";
         cin>>dvdNo;
         cout<<endl;

         cout<<"Enter Rental Period in days ";
         cin>>rentalPeriod;
         cout<<endl;

          if ((yearReleased < 1960 ) || ( runningTime < 120 ))
          {
              discount = 0.15;
              price *= discount;
          }

    //      int i, j;
      //    dvdNo[i].
            NoOfCopiesAvailable -- ;
            // = dvdCopiesAvailable -1 ;

      }

      void displayBefore1960( string &dvdTitle, int &yearReleased, int &runningTime )
    {

     if ( yearReleased < 1960 )
     {
     cout<<" Title :"<<dvdTitle;
     cout<<endl;
     cout<<" Director : "<<dName;
     cout<<endl;
     cout<<" Year of release :"<<yearReleased;
     cout<<endl;
     cout<<" Running time :"<<runningTime;
     cout<<endl;

     }
     else
     {
         cout<<"There are no dvds released before 1960. ";
         cout<<endl;
     }

    }

    void displayDiscounted ( string &dvdTitle )
    {
    if (( yearReleased < 1960 ) && ( runningTime < 120))
        {
            totalDiscounted = before1960 + under120 ;
            cout<<" Total number of discounted DvDs are :" <<totalDiscounted ;
            cout<<endl;
            cout<<" Title :"<<dvdTitle;
            cout<<endl;

        }
        else
        {
            cout<<"No dvds available for discount ";
            cout<<endl;
        }

    }
  };


int main()
{
    //Write a main program that does the following:
//• Declare an array to hold information for the DVDs available in the GreatClassics DVD store.
// The elements of the array must be of type DVD.
//• You must have member variables to hold the title of a DVD,
//the name of the director, the year released, number of copies in stock, the running time in minutes, etc.
//Initialise the array with applicable information.

string sTitle , sDirector ;

int rTime = 0, yrReleased = 0, dvdID = 0, rPeriod =0, mbrID = 0, copiesInStock = 0;

const int rows = 2, columns = 5;

dvd  clear, d , Available [rows][columns] ;

d.getTitle( sTitle) ;
//Available[rows][columns].getTitle(sTitle) =  d.getTitle( sTitle) ;

d.getRunningTime(rTime);
//Available[rows][columns].getRunningTime(rTime ) = d.getRunningTime(rTime);


d.getYearReleased(yrReleased);
//Available[rows][columns].getYearReleased(yrReleased) = d.getYearReleased(yrReleased);

d.getDirectorName(sDirector) ;
//Available[rows][columns].getDirectorName(sDirector)= d.getDirectorName(sDirector);


d.dvdCopiesAvailable(copiesInStock);
//Available[rows] [columns].dvdCopiesAvailable(copiesInStock) = d.dvdCopiesAvailable(copiesInStock);

//d [].rentOut( mbrID, dvdID, rPeriod ) = dvdsAvailable [].;

d.displayDiscounted( sTitle);

d.displayBefore1960 ( sTitle, yrReleased, rTime );


//The owner of the GreatClassics DVD store decides that he will offer a discount of 15% on all DVDs produced before 1960,
//unless they have a running time of longer than two hours.
//Display the titles, directors, year of release and running time of all DVDs produced before 1960.
//Now determine and display the number of DVDs that will be discounted and list their titles.

    return 0;
}
closed account (48T7M4Gy)
This might be a start for you to get on the right track. Your class is far too complicated because the functionality for overall inventory array, discounts and search facility should not be part of a DVD class. They can be put in main to keep it simple, or you can create other inventory or stock/sales classes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <string>

using namespace std;

class DVD{
    
private:
    string dvdTitle, director_name;
    int yearReleased = 0, running_time = 0, number_in_stock = 0;
    double price = 0.0;
    
public:
    DVD(
        string aTitle = "Name unknown", string aDirector = "?", int aYear = 0,
        int aRunTime = 0, int aNoInStock = 0, double aPrice = 0
        )
    {
        dvdTitle = aTitle;
        director_name = aDirector;
        yearReleased = aYear;
        running_time = aRunTime;
        number_in_stock = aNoInStock;
        price = aPrice;
    }
    
    string getTitle(){ return dvdTitle;};
    
    int getYear(){ return yearReleased;};
};


int main()
{
    
    // SAMPLE DATA
    DVD dvd_default;
    DVD dvd_a = DVD("Planet of the Apes", "John Smit", 1956, 123, 45, 10.50);
    DVD dvd_1 = DVD("La La Land", "Pope Francis", 1959, 250, 76, 1.50);
    DVD dvd_3 = DVD("Lion", "Donald Trump", 2017, 90, 2, 8.75);
    DVD dvd_x = DVD("Learn C++ the easy way", "Donal Duck", 1961, 145, 9, 3.20);
    
    // ARRAY OF DVD = INVENTORY
    DVD inventory[] = {dvd_default,dvd_a, dvd_1, dvd_3, dvd_x};
    size_t magnitude = sizeof(inventory)/sizeof(DVD);
    
    // DISPLAY ALL TITLES
    for(size_t i = 0; i < magnitude; i++){
        cout << inventory[i].getTitle() << '-' << inventory[i].getYear() << endl;
    }
    cout << endl;
    
    // DISPLAY ALL TITLES BEFORE 1960
    for(size_t i = 0; i < magnitude; i++)
    {
        if ( inventory[i].getYear() < 1960 ){
            cout << inventory[i].getTitle() << '-' << inventory[i].getYear() << endl;
        }
    }
    
    return 0;
}

Name unknown-0
Planet of the Apes-1956
La La Land-1959
Lion-2017
Learn C++ the easy way-1961

Name unknown-0
Planet of the Apes-1956
La La Land-1959
Program ended with exit code: 0
Last edited on
thank you for your patience and time. Greatly appreciated.

I have taken time to rethink and redo this question and have got it right just one small thing, when i change the value in rows to 2 it skips calling the function getTitle.

Please advise.

Thank you once again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include <iostream>
#include <cstring>

using namespace std;
class  dvd
{

  private:

  string dvdTitle, dName;

  int totalDiscounted, yearReleased, before1960, under120,  runningTime, NoOfCopiesAvailable ;


  public:

 int noOfrows ,index ;

 void clearValues()
 {

    totalDiscounted = 0;
    before1960 = 0;
    under120 = 0;
    runningTime = 0;
    NoOfCopiesAvailable = 0;
    noOfrows = 0;
    index  = 0;
    noOfrows = 0;

 }



  void getTitle( string &dvdTitle)
  {

      cout<<endl;
      cout<<"Enter title of dvd "<<" : ";
      getline(cin,dvdTitle);
      cout<<endl;

  }

  int getRunningTime( int &runningTime )
  {
      cout<<"Enter running time  : ";
      cin>>runningTime;
      cout<<endl;
      if( runningTime < 120 )
      {
          under120 = 0;
          under120++;
          cout<<under120<<": movie less than 120 mins available for discount"<<endl;
          cout<<endl;
      }
      else
      {
            under120 = under120;
            cout<<" No movie available for discount"<<endl;
            cout<<endl;
      }
      return under120;
  }

  int getYearReleased(int &yearReleased )
  {
      cout<<"Enter year of release : ";
      cin>>yearReleased;
      cout<<endl;
      if (yearReleased < 1960)
      {

          before1960 = 0;
          before1960++;
          cout<<before1960<<" : movie available for discount released before 1960"<<endl;
          cout<<endl;

      }
      else
      {
       // before1960 = before1960 ;


      }
      return before1960;
  }

  void getDirectorName( string &dName)
  {
      cout<<"Enter Director Name : ";
      getline(cin,dName);
      cout<<endl;

  }
    int getCopiesAvailable( int &NoOfCopiesAvailable)
    {
      NoOfCopiesAvailable = 0;
      cout<<endl;
      cout<<"Enter No of Copies Available ";
      cin>>NoOfCopiesAvailable;
      cout<<endl;
      return NoOfCopiesAvailable;
    }



      void displayBefore1960( string &dvdTitle, string &dName, int &yearReleased, int &runningTime )
    {

     if ( yearReleased < 1960 )
     {
     cout<<endl;
     cout<<" Dvds released before 1960 are :"<<endl;
     cout<<endl;
     cout<<" Title :"<<dvdTitle;
     cout<<endl;
     cout<<" Director : "<<dName;
     cout<<endl;
     cout<<" Year of release :"<<yearReleased;
     cout<<endl;
     cout<<" Running time :"<<runningTime;
     cout<<endl;

     }
     else
     {
         cout<<endl;
         cout<<"There are no dvds released before 1960, therefore no discount available. ";
         cout<<endl;

     }

    }

    void displayDiscounted ( string &dvdTitle, int &runningTime,  int &yearReleased, int &NoOfCopiesAvailable)
    {
    if  (( yearReleased < 1960 ) && ( runningTime < 120))

            {
                totalDiscounted = 0;
                totalDiscounted = before1960 *  NoOfCopiesAvailable ;
                cout<<endl;
                cout<<" Total number of discounted DvDs are :" <<totalDiscounted ;
                cout<<endl;
                cout<<" Title :"<<dvdTitle;
                cout<<endl;

            }

        else

            {
                cout<<endl;
                cout<<"  ****   No discount available *****  ";
                cout<<endl;

            }

    }
  };


int main()
{

string sTitle= "" , sDirector  = "" ;

int rTime = 0, yrReleased = 0,  copiesInStock = 0;

int rows = 1,  i = 0 ;

dvd   Available [rows] ;


for ( i = 0 ;  i < rows ; i++ )
{
    Available[rows].clearValues();

    Available[rows].getTitle(sTitle);

    Available[rows].getDirectorName(sDirector);

    Available[rows].getYearReleased(yrReleased);

    Available[rows].getRunningTime(rTime);

    Available[rows].getCopiesAvailable(copiesInStock);

    Available[rows].displayDiscounted(sTitle, rTime, yrReleased,copiesInStock );

    Available[rows].displayBefore1960( sTitle, sDirector, yrReleased, rTime );
}

    return 0;
}
closed account (48T7M4Gy)
This gets thing moving a bit. I look forward to your data model succeeding. Best wishes :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
int main()
{
    
    string sTitle= "" , sDirector  = "" ;
    
    int rTime = 0, yrReleased = 0,  copiesInStock = 0;
    
    const int rows = 5;
    
    dvd   Available [rows] ;
    
    
    for ( int i = 0 ;  i < rows ; i++ )
    {
        Available[i].clearValues();
        
        Available[i].getTitle(sTitle);
        
        Available[i].getDirectorName(sDirector);
        
        Available[i].getYearReleased(yrReleased);
        
        Available[i].getRunningTime(rTime);
        
        Available[i].getCopiesAvailable(copiesInStock);
        
        Available[i].displayDiscounted(sTitle, rTime, yrReleased,copiesInStock );
        
        Available[i].displayBefore1960( sTitle, sDirector, yrReleased, rTime );
    }
    
    return 0;
}
Topic archived. No new replies allowed.