Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an IPO chart and write C++ code to solve each of the following problem. A

ID: 3539646 • Letter: C

Question

Create an IPO chart and write C++ code to solve each of the following problem.


An office furniture company sells furniture in three colors: red, black and green. Every item in their inventory system has a 5-character code. The last two characters are always used to represent color. If an item is red, the last two characters are "41". If an item is black, the last two characters are "25". If an item is green, the last two characters are "30". Ask the user to enter a 5-character code. Use the last 2 characters to determine the color. Display the color in the console window ("Red", "Black" or "Green"). If the inventory code is not exactly 5 characters long, or if the last two characters are neither "41", "25" nor "30", display an error message ("Invalid inventory code"). [Hint: Use the substr function to extract the last two characters of the string and see whether the extracted substring is "41", "25" or "30").

INPUT

EXPECTED OUTPUT

inventory code: T4741

"Red"

INPUT

EXPECTED OUTPUT

inventory code: T4725

"Black"

INPUT

EXPECTED OUTPUT

inventory code: C4730

"Green"

INPUT

EXPECTED OUTPUT

inventory code: C4799

"Invalid inventory code"

INPUT

EXPECTED OUTPUT

inventory code: T47725

"Invalid inventory code"

INPUT

EXPECTED OUTPUT

inventory code: T4741

"Red"

Explanation / Answer

#include <iostream>

#include <string>

using namespace std;


int main()

{

string code;

cout<<"Enter the inventory code:";

cin>>code;

if(code.length()==5)

{

string key = code.substr(code.length()-2,2);

if(key == "41")

cout<<"Red"<<endl;

else if(key == "25")

cout<<"Black"<<endl;

else if(key == "30")

cout<<"Green"<<endl;

else

cout<<"Invalid Inventory Code"<<endl;

}

else

cout<<"Invalid Inventory Code"<<endl;


return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote