Algorithm and Data Structure Assignment, MUM, Malaysia Write a menu-based program to create a list of records (at least 3 data) using the queue concept
University | Monash University Malaysia (MUM) |
Subject | Algorithm and Data Structure |
Question
Write a menu-based program to create a list of records (at least 3 data) using the queue concept. Your program should be able to perform the following queue operation.
1. Enqueue
2. Dequeue
3. Queue rear
4. Queue front
4. View
5. Exit
This program is designed using a Structure which is a computer and its components. It has the ability to receive input from a user. It starts by asking the user their name. After it has been input, the screen clears, then it proceeds to ask the user if they need to fill in 5 orders for the computer with a Yes or No option.
If the user says no, the screen clears and the program will terminate. If the user says yes, the screen clears and the program proceeds to ask the user to input details such as the mainboard name, processor cores, ram size, hard disk size, and power wattage for 5 pcs. The final output then displays in a table all the components for all the PCs. If the input is invalid, the user will be asked to re-enter a valid value.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct computer
{
int ramSize, hardDrive, processorCore, powerSupply;
string mainboard;
} pc1, pc2, pc3, pc4, pc5;
string name, input;
int main()
{
cout << ” ——————– \n”;
cout << “| PC Components |\n”;
cout << ” ——————– \n\n”;
cout << “What is your name? \n”;
getline(cin >> ws, name);
cout << endl;
system (“clear”);
cout << ” ——————– \n”;
cout << “| PC Components |\n”;
cout << ” ——————– \n\n”;
cout << “Welcome ” << name << “! \n\n”;
cout << “We were told you have 5 PC orders to fill.” “\nIs this correct? \n\n”;
cout << “Press ‘Y’ for YES or ‘N’ for NO \n”;
cin >> input;
if (input == “y” || input == “Y”)
{
system (“clear”);
cout << “\nPlease Enter the components according to the PC’s. \n\n”;cout << “Enter
Components for PC1” << endl << endl;
cout << “Mainboard Brand: “;
getline (cin >> ws, pc1.mainboard);
cout << “Number of Processor Cores: “;
cin >> pc1.processorCore;
while(1)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Number of Processor Cores: “;
cin >> pc1.processorCore;
}
if(!cin.fail())
break;
}
cout << “Ram Size in Gb: “;
cin >> pc1.ramSize;
while(2)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Ram Size in Gb: “;
cin >> pc1.ramSize;
}
if(!cin.fail())
break;
}
cout << “Hard Drive Storage in Gb: “;
cin >> pc1.hardDrive;
while(3)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Hard Drive Storage in Gb: “;
cin >> pc1.hardDrive;
}
if(!cin.fail())
break; }
cout << “Power Supply Watts: “;
cin >> pc1.powerSupply;
while(4)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Power Supply Watts: “;
cin >> pc1.powerSupply;
}
if(!cin.fail())
break;
}
cout << “\nEnter Components for PC2” << endl << endl;
cout << “Mainboard Brand: “;
getline (cin >> ws, pc2.mainboard);
cout << “Number of Processor Cores: “;
cin >> pc2.processorCore;
while(1)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Number of Processor Cores: “;
cin >> pc2.processorCore;
}
if(!cin.fail())
break;
}
cout << “Ram Size in Gb: “;
cin >> pc2.ramSize;
while(2)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Ram Size in Gb: “;
cin >> pc2.ramSize; }
if(!cin.fail())
break;
}
cout << “Hard Drive Storage in Gb: “;
cin >> pc2.hardDrive;
while(3)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Hard Drive Storage in Gb: “;
cin >> pc2.hardDrive;
}
if(!cin.fail())
break;
}
cout << “Power Supply Watts: “;
cin >> pc2.powerSupply;
while(4)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Power Supply Watts: “;
cin >> pc2.powerSupply;
}
if(!cin.fail())
break;
}
cout << “\nEnter Components for PC3” << endl << endl;
cout << “Mainboard Brand: “;
getline (cin >> ws, pc3.mainboard);
cout << “Number of Processor Cores: “;
cin >> pc3.processorCore;
while(1)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Number of Processor Cores: “;
cin >> pc3.processorCore;
}
if(!cin.fail())
break;
}
cout << “Ram Size in Gb: “;
cin >> pc3.ramSize;
while(2)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Ram Size in Gb: “;
cin >> pc3.ramSize;
}
if(!cin.fail())
break;
}
cout << “Hard Drive Storage in Gb: “;
cin >> pc3.hardDrive;
while(3)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Hard Drive Storage in Gb: “;
cin >> pc3.hardDrive;
}
if(!cin.fail())
break;
}
cout << “Power Supply Watts: “;
cin >> pc3.powerSupply;
while(4)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Power Supply Watts: “;
cin >> pc3.powerSupply; }
if(!cin.fail())
break;
}
cout << “\nEnter Components for PC4” << endl << endl;
cout << “Mainboard Brand: “;
getline (cin >> ws, pc4.mainboard);
cout << “Number of Processor Cores: “;
cin >> pc4.processorCore;
while(1)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Number of Processor Cores: “;
cin >> pc4.processorCore;
}
if(!cin.fail())
break;
}
cout << “Ram Size in Gb: “;
cin >> pc4.ramSize;
while(2)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Ram Size in Gb: “;
cin >> pc4.ramSize;
}
if(!cin.fail())
break;
}
cout << “Hard Drive Storage in Gb: “;
cin >> pc4.hardDrive;
while(3)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Hard Drive Storage in Gb: “;
cin >> pc4.hardDrive;
}
if(!cin.fail())
break;
}
cout << “Power Supply Watts: “;
cin >> pc4.powerSupply;
while(4)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Power Supply Watts: “;
cin >> pc4.powerSupply;
}
if(!cin.fail())
break;
}
cout << “\nEnter Components for PC5” << endl << endl;
cout << “Mainboard Brand: “;
getline (cin >> ws, pc5.mainboard);
cout << “Number of Processor Cores: “;
cin >> pc5.processorCore;
while(1)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Number of Processor Cores: “;
cin >> pc5.processorCore;
}
if(!cin.fail())
break;
}
cout << “Ram Size in Gb: “;
cin >> pc5.ramSize;
while(2)
{
if(cin.fail())
{
cin.clear(); cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Ram Size in Gb: “;
cin >> pc5.ramSize;
}
if(!cin.fail())
break;
}
cout << “Hard Drive Storage in Gb: “;
cin >> pc5.hardDrive;
while(3)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Hard Drive Storage in Gb: “;
cin >> pc5.hardDrive;
}
if(!cin.fail())
break;
}
cout << “Power Supply Watts: “;
cin >> pc5.powerSupply;
while(4)
{
if(cin.fail())
{
cin.clear();
cin.ignore();
cout<<“You have entered an invalid input!”<<endl;
cout << “Power Supply Watts: “;
cin >> pc5.powerSupply;
}
if(!cin.fail())
break;
}
cout << “\n ——————————– \n”;
cout << “| Overview of PC Components |\n”;
cout << ” ——————————– \n\n”;
cout << setw(2) << ” ” << setfill (‘-‘) << setw(115) << “-” << endl;
cout << fixed << setprecision(2) << setfill (‘ ‘);cout << setw(2) << ” ” << “| Component | ” <<
setw(14) << “| PC 1 |”
<< setw(18) << “| PC 2 |” << setw(18) << “| PC 3 |” << setw(18) << “| PC 4 |”
<< setw(18) << “| PC 5 |” << endl << endl;
cout << setw (4) << ” ” << setw(9) << “Mainboard” << setw(18) << ” ”
<< pc1.mainboard << setw(10) << ” ” << left
<< pc2.mainboard << setw(10) << ” ” << left
<< pc3.mainboard << setw(10) << ” ” << left
<< pc4.mainboard << setw(10) << ” ” << left
<< pc5.mainboard << setw(10) << ” ” << left << endl;
cout << setw (4) << ” ” << setw(9) << “Processor Cores” << setw(12) << ” ”
<< pc1.processorCore << ” cores” << setw(11) << ” ” << left
<< pc2.processorCore << ” cores” << setw(11) << ” ” << left
<< pc3.processorCore << ” cores” << setw(11) << ” ” << left
<< pc4.processorCore << ” cores” << setw(11) << ” ” << left
<< pc5.processorCore << ” cores” << setw(10) << ” ” << left
<< endl;
cout << setw (4) << ” ” << setw(9) << “Ram (GB)” << setw(18) << ” ”
<< pc1.ramSize << ” Gb” << setw(13) << ” ” << left
<< pc2.ramSize << ” Gb” << setw(13) << ” ” << left
<< pc3.ramSize << ” Gb” << setw(13) << ” ” << left
<< pc4.ramSize << ” Gb” << setw(13) << ” ” << left
<< pc5.ramSize << ” Gb” << setw(13) << ” ” << left
<< endl;
cout << setw (4) << ” ” << setw(7) << “Hard Drive (GB)” << setw(12) << ” ”
<< pc1.hardDrive << ” Gb” << setw(12) << ” ” << left
<< pc2.hardDrive << ” Gb” << setw(12) << ” ” << left
<< pc3.hardDrive << ” Gb” << setw(12) << ” ” << left
<< pc4.hardDrive << ” Gb” << setw(12) << ” ” << left
<< pc5.hardDrive << ” Gb” << setw(12) << ” ” << left
<< endl;
cout << setw (4) << ” ” << setw(9) << “Power Supply (Watts)” << setw(7) << ”
”
<< pc1.powerSupply << ” Watts” << setw(9) << ” ” << left
<< pc2.powerSupply << ” Watts” << setw(9) << ” ” << left
<< pc3.powerSupply << ” Watts” << setw(9) << ” ” << left
<< pc4.powerSupply << ” Watts” << setw(9) << ” ” << left
<< pc5.powerSupply << ” Watts” << setw(9) << ” ” << left
<< endl;
cout << setw(2) << ” ” << setfill (‘-‘) << setw(115) << “-” << setfill (‘ ‘) << endl
<< left;
return 0;
}else if (input == “n” || input == “N”)
{
system (“clear”);
cout << “\nOh my apologies! Goodbye! \n”;
return 0;
}
cout << “Thank you for placing your order!”;
return 0;
}
Stuck in Completing this Assignment and feeling stressed ? Take our Private Writing Services.
Get Help By Expert
Assignmenthelper.my is the ultimate homework help online platform. We provide students with high-quality and affordable services that ensure success in their homework and assignments. With our exceptional writing service, you can take your studies to a higher level without having to worry about getting good grades.
Recent Solved Questions
- CBCA2103: Computer Architecture Assignment, OUM, Malaysia The purpose of this assignment is to assess learners’ understanding of CPU organization, instructions format, and addressing mode
- NBHS1112: Vitamins and minerals are micronutrients that cannot be synthesized by the body: Biochemistry Assignment, OUM, Malaysia
- English Language Proficiency Essay, UOM, UK Alexander the Great’s conquest of much of the Western world in the 4th century BC gave Hellenistic travelers
- MPU3192: Bincangkan falsafah di sebalik filem tersebut dan kaitkan dengan falsafah praktikal dalam kehidupan: Falsafah dan isu Semasa 2 Assignment, OUM, Malaysia
- AAPP003-3-C: Outline algorithms using computing logic to solve a problem: Fundamentals of Visual Programming, Individual Assignment, APU, Malaysia
- PHYS1010D: A basketball player attempts to siioor from the position as shown in FIGURE 1 below. The angle o is the shooting angle: General Physics Assignment, Singapore
- BBAP4103: Investment Analysis Assignment, OUM, Malaysia Choose TWO companies listed in the transportation & logistics sector of the Main Market of Bursa Malaysia. Find the companies
- ECW1101: Introductory Microeconomics Essay, MUM, Malaysia Explain why the world price of palm oil increases as the result of the impact of Russia-Ukraine conflict
- CSC404: Programming II Assignment, UiTM, Malaysia UiTM Johor will organize an Active Learning Workshop among lecturers from UiTM and other universities in Malaysia
- Business Law Assignment, UCSI, Malaysia Discuss the relationship between Company Law and Consumer Protection Law in Malaysia