names from array

This is the output i want outputted after information is inputted. instead of my
code that skips the 1st name info.
Day of Week: Wednesday
No of painters: 2
Name 1: Jack
Name 2: Zee
---------------------------------------------
Day of Week: Thursday
No of painters: 1
Name: Zee
********employee wages**********
Name: Zee
Hrs works: 6 at R5.75 an hr. Total wages: R34.50
Day of week:Wednesday, Thursday
-----------------------------------------------
Name: Jack
Hrs works: 3 at R5.75 an hr. Total wages: R17.25
Day of week:Wednesday
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
  #include <iostream>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;

class bBuilding
{
private:
	static const size_t NR_BUILINGS=2;
	int addressN[NR_BUILINGS];
	string addressS[NR_BUILINGS];
	
	string dOWeek[NR_BUILINGS];
	int noPainters[NR_BUILINGS];
	string paintersN[NR_BUILINGS];
	string choice[NR_BUILINGS];
	int numHrs[NR_BUILINGS];
	
public:

	void getPaintersDetails()
	{
	for (size_t count = 0; count<NR_BUILINGS; ++count)
{
	
cout<<"Address number then Street name ";
cin>>addressN[count]; cin.ignore(); getline(cin, addressS[count]);
cout<<"Please enter Day of Week serviced: ";
getline(cin,dOWeek[count]);
cout<<"Number of painters who worked on that day: ";
cin>>noPainters[count];
cin.ignore();
for (int i=0; i<noPainters[count]; i++)
	{   cout << "Name of the Painter " << i+1 << "? ";
         cin>>paintersN[count];
		cin.ignore();}
numHrs[count]=3;

	cout<<"--------------------------------------------------------"<<endl;
		
}
	}


void wages()
	{cout<<"*************************"<<setw(16)<<"ALL EMPLOYEES WAGES"<<"**************************"<<endl;
    for( size_t count = 0; count < NR_BUILINGS; ++count )
    {
     const string& name = paintersN[count] ;
     if( !name.empty() ) // if this is a name that was not already processed
    {
        cout << "Name: " << name << '\n' ;
	int paintersHr=numHrs[count];
	//iterate through the array to see if name appears again
 for( size_t i = count+1; i < NR_BUILINGS; ++i ) 
	 if( paintersN[i] == name )
                      paintersHr += numHrs[i] ;
 
 double price = 5.75;
  cout << "Hours worked: " << paintersHr <<" at R5.75 an hr. "<< " Total wages: "
                               <<fixed <<setprecision(2) <<"R"<<paintersHr * price << '\n' ;

   cout << "Day of week: " << dOWeek[count] ;
                     // iterate through the array to see if this name appears again
                     for( size_t i = count+1; i < NR_BUILINGS; ++i ) if( paintersN[i] == name )
                     {
                          cout << ' '<<"," << dOWeek[i] ;
                          paintersN[i] = "" ; // we are done with this name, we don't want to process it again
                     }

                     cout << "\n\n" ;
					 cout<<"----------------------------------------------------------------"<<endl;
                 }
             }
         }
	};


int main()
{
 bBuilding e1;
 e1.getPaintersDetails();

 e1.wages();
}
Line 36: You can only store one painter in paintersN[count].

You're misusing your class. Since everything in your class occurs NR_BUILINGS times, it should be the instance at line 82 that occurs NR_BUILINGS times. Your member variables should occur once (except painterN) and not occur NR_BUILINGS times. Each instance of bBuilding should refer to ONE building or job.

paintersN should occur MAX_PAINTERS times (whatever that value is).

1
2
3
4
5
6
7
8
9
10
11
12
class bBuilding
{   int addressN;
	string addressS;
	string dOWeek;
	int noPainters;
	string paintersN[MAX_PAINTERS];
	string choice;
	int numHrs;	
public:
    void getPaintersDetails();
    void wages();
};

Reason i used the const NR_Buildings is because there are 2 building and painters can be more then 1.
Last edited on
You're missing the point. Your class should represent ONE building or job, not a collection of such. You want a collection of buildings or jobs, use a std::vector or an array of instances of your class.
Last edited on
Topic archived. No new replies allowed.