Esempio n. 1
0
void compare(const Sale &s1, const Sale &s2) {
	if (s1 < s2) {
		cout << "Prviot e poeftin.\n";
	} else
		cout << "Vtoriot e poeftin.\n";
	cout << "Zastedata e " << fabs(s2.savings(s1)) << " den.\n";
}
Esempio n. 2
0
void Widget::on_listWidget_2_itemClicked(QListWidgetItem *item)
{
    int index = ui->listWidget_2->row(item);
    if (this->top5.empty()){
        Sale *selectedSale = this->controller->getSaleForId(this->saleIds[index]);
        if (selectedSale->getMedication() == NULL){
            ui->medName_2->setText("Not Set");
            ui->saleDate->clear();
            ui->saleQuantity->clear();
        } else {
            ui->medName_2->setText(QString::fromStdString(selectedSale->getMedication()->getName()));
            ui->saleDate->setValue(selectedSale->getDate());
            ui->saleQuantity->setText(QString::fromStdString(to_string(selectedSale->getQuantity())));
        }
    } else {
        ui->medName_2->setText(QString::fromStdString(this->top5[index].getMedication()->getName()));
        ui->saleQuantity->setText(QString::fromStdString(to_string(this->top5[index].getQuantity())));
    }

}
Esempio n. 3
0
 bool operator <(const Sale& first, const Sale& second)
 {
   // Because of polymorphism, will correctly apply subclass method
   // bill() instead of superclass method if subclass method implemented.
   return (first.bill() < second.bill());
 }
Esempio n. 4
0
 double Sale::savings(const Sale& other) const
 {
   return (bill() - other.bill());
 }
void AdDisplayMenu::print() {
	//first line, only borderChar
	for (unsigned int i = 0; i < width; i++)
		cout << borderChar;

	cout << endl;

	//includes top margin with is a line full of spaces, with borderChar on either side
	for (unsigned int i = 0; i < topMargin; i++)
		emptyLine();

	cout << borderChar << " ";
	string adType;
	if (ad->getType() == 'P')
		adType = "Purchase";
	else
		adType = "Sale";
	adType += " Ad";

	cout << adType << string(width - 3 - adType.length(), ' ') << borderChar << endl;
	emptyLine();

	//display title
	string title = ad->getTitle();
	cout << borderChar << " Title: " << title
			<< string(width - 2 - 8 - title.length(), ' ') << borderChar << endl;

	//a white line between title and description
	emptyLine();

	cout << borderChar << " Category: " << categoryToString(ad->getCategory())
			<< string(
					width - 2 - 11
							- categoryToString(ad->getCategory()).length(), ' ')
			<< borderChar << endl;

	emptyLine();

	//used to add menu options correctly
	string description = ad->getDescription();

	cout << borderChar << " Description: " << description
			<< string(width - 2 - 14 - description.length(), ' ') << borderChar
			<< endl;

	if(ad->getType() == 'S'){
		emptyLine();
		Sale* sale = static_cast<Sale*> (ad);
		string cond = conditionToString(sale->getCondition());
		cout << borderChar << " Product Condition: " << cond << string(width-2-20- cond.length(), ' ') << borderChar << endl;
	}


	//a white line between description and contacts
	emptyLine();

	cout << borderChar << " Creation Date: " << ad->getCreationDate()
			<< string(width - 2 - 16 - ad->getCreationDate().length(), ' ')
			<< borderChar << endl;

	bool showEmail = ad->getOwner()->getShowEmail();
	bool showName = ad->getOwner()->getShowName();
	bool showPhoneNumber = ad->getOwner()->getShowPhoneNumber();

	if (showEmail || showName || showPhoneNumber) {
		if (showEmail) {
			string email = ad->getOwner()->getEmail();
			cout << borderChar << " Email: " << email
					<< string(width - 2 - 8 - email.length(), ' ') << borderChar
					<< endl;
		}

		if (showName) {
			string name = ad->getOwner()->getName();
			cout << borderChar << " Name: " << name
					<< string(width - 2 - 7 - name.length(), ' ') << borderChar
					<< endl;
		}

		if (showPhoneNumber) {
			string phoneNumber = ad->getOwner()->getPhoneNumber();
			cout << borderChar << " Phone Number: " << phoneNumber
					<< string(width - 2 - 15 - phoneNumber.length(), ' ')
					<< borderChar << endl;
		}
		emptyLine();
	}
	stringstream ss;
	ss << ad->getViews();
	cout << borderChar << " Views: " << ss.str()
			<< string(width - 2 - 8 - ss.str().length(), ' ') << borderChar
			<< endl;
	emptyLine();

	ss.str("");
	ss << ad->getPrice() << "  ";
	if (!ad->isPriceNegotiable())
		ss << "Non-";
	ss << "Negotiable";
	cout << borderChar << " Price: " << ss.str()
			<< string(width - 2 - 8 - ss.str().length(), ' ') << borderChar
			<< endl;
	emptyLine();

	unsigned int i = 1;
	if (data->getSignedInUser() == ad->getOwner()) {
		string editTitle = "1 - Edit title";
		cout << borderChar << " " << editTitle
				<< string(width - 3 - editTitle.length(), ' ') << borderChar
				<< endl;
		string editDescription = "2 - Edit description";
		cout << borderChar << " " << editDescription
				<< string(width - 3 - editDescription.length(), ' ')
				<< borderChar << endl;
		string editCategory = "3 - Edit category";
		cout << borderChar << " " << editCategory
				<< string(width - 3 - editCategory.length(), ' ') << borderChar
				<< endl;
		string editPrice = "4 - Edit price";
		cout << borderChar << " " << editPrice
				<< string(width - 3 - editPrice.length(), ' ') << borderChar
				<< endl;
		string removeAd = "5 - Remove advertisement";
		cout << borderChar << " " << removeAd
				<< string(width - 3 - removeAd.length(), ' ') << borderChar
				<< endl;
		i = 6;
	} else {
		string imInterested = " 1 - I'm interested";
		i = 2;
		cout << borderChar << imInterested
				<< string(width - imInterested.length() - 2, ' ') << borderChar
				<< endl;
	}
	ss.str("");
	ss << " " << i << " - Exit";
	cout << borderChar << ss.str() << string(width - ss.str().length() - 2, ' ')
			<< borderChar << endl;

	emptyLine();

	//last line
	for (unsigned int i = 0; i < width; i++)
		cout << borderChar;

	cout << endl;
}
Esempio n. 6
0
bool operator <(const Sale& first, const Sale& second) {
	return (first.bill() < second.bill());
}