Skip to content
Permalink
Browse files

Step 1: extracting the body of the of the for loop

  • Loading branch information
sandordargo committed Jul 23, 2018
1 parent ddb2d02 commit 65a26523958d1c6b7eb2f9e8d81cf80492a8adc8
Showing with 49 additions and 56 deletions.
  1. +47 −56 cpp/GildedRose.cc
  2. +2 −0 cpp/GildedRose.h
@@ -3,78 +3,69 @@
GildedRose::GildedRose(vector<Item> & items) : items(items)
{}

void GildedRose::updateQuality()
void GildedRose::processItem(Item & item)
{
for (int i = 0; i < items.size(); i++)
{
if (items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert")
{
if (items[i].quality > 0)
{
if (items[i].name != "Sulfuras, Hand of Ragnaros")
{
items[i].quality = items[i].quality - 1;
}
if(item.name != "Aged Brie" && item.name != "Backstage passes to a TAFKAL80ETC concert"){
if(item.quality > 0){
if(item.name != "Sulfuras, Hand of Ragnaros"){
item.quality = item.quality - 1;
}
}
else
{
if (items[i].quality < 50)
{
items[i].quality = items[i].quality + 1;

if (items[i].name == "Backstage passes to a TAFKAL80ETC concert")
{
if (items[i].sellIn < 11)
{
if (items[i].quality < 50)
{
items[i].quality = items[i].quality + 1;
}
}
else{
if(item.quality < 50){
item.quality = item.quality + 1;
if(item.name == "Backstage passes to a TAFKAL80ETC concert"){
if(item.sellIn < 11){
if(item.quality < 50){
item.quality = item.quality + 1;
}
}

if (items[i].sellIn < 6)
{
if (items[i].quality < 50)
{
items[i].quality = items[i].quality + 1;
}
if(item.sellIn < 6){
if(item.quality < 50){
item.quality = item.quality + 1;
}
}

}
}

if (items[i].name != "Sulfuras, Hand of Ragnaros")
{
items[i].sellIn = items[i].sellIn - 1;
}

if (items[i].sellIn < 0)
{
if (items[i].name != "Aged Brie")
{
if (items[i].name != "Backstage passes to a TAFKAL80ETC concert")
{
if (items[i].quality > 0)
{
if (items[i].name != "Sulfuras, Hand of Ragnaros")
{
items[i].quality = items[i].quality - 1;
}
}

if(item.name != "Sulfuras, Hand of Ragnaros"){
item.sellIn = item.sellIn - 1;
}
if(item.sellIn < 0){
if(item.name != "Aged Brie"){
if(item.name != "Backstage passes to a TAFKAL80ETC concert"){
if(item.quality > 0){
if(item.name != "Sulfuras, Hand of Ragnaros"){
item.quality = item.quality - 1;
}
}
else
{
items[i].quality = items[i].quality - items[i].quality;
}

}
else
{
if (items[i].quality < 50)
{
items[i].quality = items[i].quality + 1;
}
else{
item.quality = item.quality - item.quality;
}
}
else{
if(item.quality < 50){
item.quality = item.quality + 1;
}
}

}

}

void GildedRose::updateQuality()
{
for (Item & item: items)
{
processItem(item);
}
}
@@ -20,5 +20,7 @@ class GildedRose
GildedRose(vector<Item> & items);

void updateQuality();
private:
void processItem(Item & item);
};

0 comments on commit 65a2652

Please sign in to comment.
You can’t perform that action at this time.