Question

PROGRAMMING LANGUAGE OOP'S WITH C++ Functional Requirements: A jewelry designer friend of mine requires a program...

PROGRAMMING LANGUAGE OOP'S WITH C++

Functional Requirements:

A jewelry designer friend of mine requires a program to hold information about the gemstones he has in his safe.

Offer the jewelry designer the following menu that loops until he chooses option 4.

1. Input a gemstone

2. Search for a gemstone by ID number

3. Display all gemstone information with total value

4. Exit

-------------------------------------

Gemstone data:

ID number (int > 0, must be unique)

Gem Name (string, length < 15)

Gem Weight in carats: (float, >=0)

Amount Paid (float, >=0)

Rating (*, **, ***, ****, *****; rating must be one of those 5 choices)

----------------------------------------

Programming Requirements:

Above main(), create a structure that will hold the information listed above. Then inside of main() create an array of 25 structures. Each structure in the array will represent one different gemstone.

Display the menu and loop through the choices as follows:

Option 1: Pass the array of structures to a function that inputs and validates as indicated above.

Option 2. Pass the array of structures to a function which allows the user to search for a gemstone by ID number and then display that gemstone information. If that ID number does not exist, display a message to that effect.

Option 3. Pass the array of structures to a function that displays all gemstone information AND the total value of all gemstones (which your program will calculate).

Option 4. Exist the program.

PLEASE PROVIDE THE OUTPUT .THANK YOU

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:

#include <iostream>

#include<string>

#include <iomanip>

using namespace std;

struct Gem{

int id;

string name;

float weight;

float amountPaid;

int rating;

};

void printMenu(){

cout<<"Select an option"<<endl;

cout<<"1. Input a gemstone"<<endl;

cout<<"2. Search for a gemstone by ID number"<<endl;

cout<<"3. Display all gemstone information with total value"<<endl;

cout<<"4. Exit"<<endl;

cout<<"Enter your choice : ";

}

void addGem(Gem * gems,int& index){

int id;

string name;

float weight;

float amount;

int rating;

if(index==25){

cout<<"Cannot add more gems"<<endl;

return ;

}

while(true){

cout<<"Enter id : ";

cin>>id;

if(id<=0){

cout<<"Id should be greater than 0"<<endl;

}else{

bool found = false;

for(int i=0;i<index;i++){

if(id==gems[i].id){

cout<<"Id should be unique"<<endl;

found = true;

break;

}

}

if(!found){

break;

}

}

}

while(true){

cout<<"Enter Gem Name : ";

cin>>name;

if(name.length()<15){

break;

}else{

cout<<"Name length should be less than 15"<<endl;

}

}

while(true){

cout<<"Enter Gem Weight : ";

cin>>weight;

if(weight>0){

break;

}else{

cout<<"Weight should be greater than 0"<<endl;

}

}

while(true){

cout<<"Enter Gem Amount : ";

cin>>amount;

if(amount>0){

break;

}else{

cout<<"Amount should be greater than 0"<<endl;

}

}

while(true){

cout<<"Enter Gem Rating : ";

cin>>rating;

if(rating>=1 && rating<=5){

break;

}else{

cout<<"Rating should be 1 to 5"<<endl;

}

}

gems[index].id =id;

gems[index].name =name;

gems[index].weight=weight;

gems[index].amountPaid =amount;

gems[index].rating =rating;

index++;

}

void searchGem(Gem * gems,int totalGem){

int id;

cout<<"Enter id : ";

while(true){

cin>>id;

if(id<=0){

cout<<"Id should be greater than 0"<<endl;

}else{

break;

}

}

for(int i=0;i<totalGem;i++){

if(id==gems[i].id){

cout << setw(10) << left <<"Id";

cout << setw(20) << left <<"Name";

cout << setw(10) << left <<"Weight";

cout << setw(10) << left <<"Amount";

cout << setw(10) << left <<"Rating";

cout<<endl;

for(int i=0;i<totalGem;i++){

cout << setw(10) << left <<gems[i].id;

cout << setw(20) << left <<gems[i].name;

cout << setw(10) << left <<gems[i].weight;

cout << setw(10) << left <<gems[i].amountPaid;

cout << setw(10) << left <<gems[i].rating;

cout<<endl;

}

return ;

}

}

cout<<"Gem with id not found!!!";

return;

}

void displayGemInfo(Gem * gems,int totalGem){

cout << setw(10) << left <<"Id";

cout << setw(20) << left <<"Name";

cout << setw(10) << left <<"Weight";

cout << setw(10) << left <<"Amount";

cout << setw(10) << left <<"Rating";

cout<<endl;

float total =0;

for(int i=0;i<totalGem;i++){

cout << setw(10) << left <<gems[i].id;

cout << setw(20) << left <<gems[i].name;

cout << setw(10) << left <<gems[i].weight;

cout << setw(10) << left <<gems[i].amountPaid;

cout << setw(10) << left <<gems[i].rating;

total+=gems[i].amountPaid;

cout<<endl;

}

cout<<"==============================="<<endl;

cout<<"Total value is : "<<total<<endl;

}

int main()

{

Gem gems[25];

int totalGem=0;

int choice;

cout << fixed << showpoint << setprecision(2);

while(true){

printMenu();

cin>>choice;

if(choice==1){

addGem(gems,totalGem);

}else if(choice==2){

searchGem(gems,totalGem);

}else if(choice==3){

displayGemInfo(gems,totalGem);

}else if(choice==4){

break;

}else{

cout<<"Invalid choice!!!";

}

cout<<endl<<endl;

}

return 0;

}

output:

Enter Gem Rating : 4 Select an option 1. Input a gemstone 2. Search for a gemstone by ID number 3. Display all gemstone information with total value 4. Exit Enter your choice: 1 Enter id :1 Id should be unique Enter id : 2 Enter Gem Name ruby Enter Gem Weight: 3 Enter Gem Amount : 898349 Enter Gem Rating: 5 Select an option 1. Input a gemstone 2. Search for a gemstone by ID number 3. Display all gemstone information with total value 4. Exit Enter your choice: 3 Id 1 Name saphire ruby Weight AmountRating 4.00 3.00 898989.00 4 898349.00 5 Total value is 1797338.00 Select an option 1. Input a gemstone 2. Search for a gemstone by ID number 3. Display all gemstone information with total value 4. Exit Enter your choice: 4

Add a comment
Know the answer?
Add Answer to:
PROGRAMMING LANGUAGE OOP'S WITH C++ Functional Requirements: A jewelry designer friend of mine requires a program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Show data: Show Name (string- up to 25 characters, may not be blank) Show Date (mm/dd/yyyy,...

    Show data: Show Name (string- up to 25 characters, may not be blank) Show Date (mm/dd/yyyy, in that format) Show Fee to Participate (float, >-0) Show Sales (float, >-0) Miscellaneous Costs (float, >-0) Rate the Show(rating must be one of those 5 choices) Above maino, create a structure that will hold the information listed above. Then inside of main) create an array of 10 structures. Each structure in the array will represent a different show. Rules of the program: Option...

  • THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...

    THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #include "pch.h" #include #include using namespace std; // Function prototype void displayMessage(void); void totalFees(void); double calculateFees(int); double calculateFees(int bags) {    return bags * 30.0; } void displayMessage(void) {    cout << "This program calculates the total amount of checked bag fees." << endl; } void totalFees() {    double bags = 0;    cout << "Enter the amount of checked bags you have." << endl;    cout <<...

  • In C Program This program will store the roster and rating information for a soccer team. There w...

    In C Program This program will store the roster and rating information for a soccer team. There will be 3 pieces of information about each player: Name: string, 1-100 characters (nickname or first name only, NO SPACES) Jersey Number: integer, 1-99 (these must be unique) Rating: double, 0.0-100.0 You must create a struct called "playData" to hold all the information defined above for a single player. You must use an array of your structs to to store this information. You...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one...

    In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT