operator <() function

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
/*
Title		: Lab Task 4 Question 3
Author		: Lim Boon Jye
Description	: Operator Overloading
Date		: 13 September 2012
*/
#include <iostream>
#include <string>

using namespace std;

class Jobbid{
public:
	int bidNum ;
	double quotedPrice;

	//Jobbid();
	//~Jobbid();
	//void displayLowest();

	bool operator < (const Jobbid& j) const {
		if( quotedPrice < j.quotedPrice ){
			return true;
		}
		if( quotedPrice > j.quotedPrice ){
			return false;
		}
	}
     //int Bid() { return bidNum; }
      //int Qoute() { return quotedPrice; }

};

//void Jobbid :: displayLowest(){
//
//}

int main()
{
	Jobbid thejobbid[4];
	int arrayOfbid[4];
	double priceQuoted[4];

	for( int i = 0 ; i < 4 ; i++ ){
		cout << "Enter Bid Number : ";
		cin  >> thejobbid[i].bidNum;

		cout << "Enter quote price: ";
		cin  >> thejobbid[i].quotedPrice;;
	}

	for( int i = 0 ; i < 4 ; i++ ){
		if ( thejobbid[i].quotedPrice < thejobbid[i+1].quotedPrice ){
			cout << thejobbid[i+1].bidNum << " more than " << thejobbid[i].bidNum <<endl;
		}
		else if ( thejobbid[i].quotedPrice > thejobbid[i+1].quotedPrice ){
			cout << thejobbid[i+1].bidNum << " less than " << thejobbid[i].bidNum <<endl;
		}
	}
	cin.ignore();
	cin.get();
	return 0;
}


My code is wrong . can any senior try to help?
I've to create 4 array of the Object
I have to display the lowest Quoted price with their Bid Number ID
Have to use overloaded operator <()
Cannot use constructor to set field values

so , where my code wrong?

My sample out
1
2
3
4
5
6
7
8
9
10
11
12
Enter Bid Number : 0413
Quoted Price     : 50.00
Enter Bid Number : 0414
Quoted Price     : 50.05
Enter Bid Number : 0415
Quoted Price     : 60.00
Enter Bid Number : 0416
Quoted Price     : 20.00


Lowest Price Quote is : RM 20
Bid Number ID is      : 0416


but I not really sure how to do it.. need to use overloaded array
Last edited on
Topic archived. No new replies allowed.