USING ARRAY IN C++ PROGRAMMING BUT DONT USE STRUCTURE FOR THIS PROGRAM ONLY ARRA
ID: 3755984 • Letter: U
Question
USING ARRAY IN C++ PROGRAMMING BUT DONT USE STRUCTURE FOR THIS PROGRAM ONLY ARRAY
Functional Requirements: A looping, menu-driven program that allows my friend, the restaurant designer, to store information about his jobs including customer name, restaurant name, contract value, and how much has been paid-to-date on the contract. Offer the designer the following menu that loops until they choose option 5.
1. Input a customer's information
2. Edit a customer's information
3. Search for contracts by value
4. Display all contract information
5. Exit -------------------------------------
Customer information Name (string - up to 15 characters, may not be blank)
Restaurant (string - up to 15 characters, may not be blank)
Contract Value (float >=0)
Paid-To_Date on Contract: (float >=0) ----------------------------------------
In main() create 4 parallel arrays that will hold the data for my friend. (You may NOT utilize structures for this assignment - we are working on parallel arrays here.) string customer [10] string restaurant [10] float contract[10] float paidToDate[10]
Create a looping menu (see pseudocode in this lesson) which accomplishes the following:
Menu Option 1: Pass the 4 arrays to a function that inputs and validates and stores customer data for ONE CUSTOMER. Make sure that you are counting the number of customers as you go so that you don't allow more then 10 customers to be input.
Menu Option 2: Pass the 4 arrays to a function that prompts the user for which customer to edit and then prompts the user for what field to edit. Accept and validate the edit. Store the data into the arrays.
Option 3. Pass the 4 arrays to a function that prompts the user for a contract amount and then displays all the contracts that are >= that amount.
Option 4. Pass the 4 array to a function that displays all the information AND the total of all the contracts (which your program will calculate).
Option 5. Exist the program.
Make sure to design modular code. If you have code that is repeated then call one function to handle it. No global variables - but you may use global constants.
Use cin.ignore() before your getlines. If this is too confusing, then you can just take a 3-pt deduction and only use cin. ----------------------------------------
Option 4 Sample Output To earn full credit on your output, you will need to use the iomanip library to create columns of data with proper headers, dollar amounts that have proper decimal places and the $.
Make your output look professional. ****************************************************************************************************************************************************** Restaurant Client Information ****************************************************************************************************************************************************** Name Restaurant Contract Value Paid-to-Date John Jones Local $ 25,600.00 $ 10,000.00 Kevin McQueen Green Leaf $ 6,250.45 $ 3,500.00 Total of All Contracts: $31,850.45 ----------------------------------------
Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
int add_data(string name[],string restaurant[],float value[],float pade_to_date[],int count);
int edit_data(string name[],string restaurant[],float value[],float pade_to_date[],int count);
int search_data(string name[],string restaurant[],float value[],float pade_to_date[],int count);
int display_data(string name[],string restaurant[],float value[],float pade_to_date[],int count);
int main()
{
int ch=-1,count=0;
float value[10],pade_to_date[10];
string name[10],restaurant[10];
while(ch!=5)
{
ch=-1;
cout<<"1. Input a customer's information"<<endl;
cout<<"2. Edit a customer's information"<<endl;
cout<<"3. Search for contracts by value"<<endl;
cout<<"4. Display all contract information"<<endl;
cout<<"5. Exit -------------------------------------"<<endl;
while(ch<1||ch>5)
{
cout<<"Enter your choice:";
cin>>ch;
if(ch<1||ch>5)
{
cout<<"Invalid Choice"<<endl;
}
switch(ch)
{
case 1:
if(count<10)
{
count=add_data(name,restaurant,value,pade_to_date,count);
}
else
{
cout<<" Infufficient Space ";
}
break;
case 2:
if(count>0)
{
edit_data(name,restaurant,value,pade_to_date,count);
}
else
{
cout<<" No data found ";
}
break;
case 3:
if(count>0)
{
search_data(name,restaurant,value,pade_to_date,count);
}
else
{
cout<<" No data found. ";
}
break;
case 4:
if(count>0)
{
display_data(name,restaurant,value,pade_to_date,count);
}
else
{
cout<<" No data found. ";
}
break;
}
}
}
}
int add_data(string _name[],string _restaurant[],float _value[],float _pade_to_date[],int count)
{
string name="Text_greater_then_15_character";
float temp_data=-1;
while(name.length()>15)
{
cout<<" Enter Name:";
cin>>name;
if(name.length()>15)
{
cout<<" Name should be less then 15 character ";
}
}
_name[count]=name;
name="Text_greater_then_15_character";
while(name.length()>15)
{
cout<<" Enter Resturent name:";
cin>>name;
if(name.length()>15)
{
cout<<" Resturent Name should be less then 15 character ";
}
}
_restaurant[count]=name;
while(temp_data<0)
{
cout<<" Enter Value:";
cin>>temp_data;
if(temp_data<0)
{
cout<<" Value should be greater then 0 ";
}
}
_value[count]=temp_data;
temp_data=-1;
while(temp_data<0)
{
cout<<" Enter Pade-to-date:";
cin>>temp_data;
if(temp_data<0)
{
cout<<" Pade-to-date Value should be greater then 0 ";
}
}
_pade_to_date[count]=temp_data;
return ++count;
}
int edit_data(string _name[],string _restaurant[],float _value[],float _pade_to_date[],int count)
{
string name;
cout<<"Enter name to search the required field:";
cin>>name;
int index=-1;
for(int i=0;i<count;i++)
{
if(_name[i]==name)
{
index=i;
break;
}
}
if(index!=-1)
{
int temp_ch=-1;
cout<<" 1:For Edit name";
cout<<" 2:For Edit resturent";
cout<<" 3:For Edit value";
cout<<" 4:For Edit pade-to-date";
while(temp_ch<0||temp_ch>5)
{
cout<<" Enter your choice:";
cin>>temp_ch;
if(temp_ch<0||temp_ch>4)
{
cout<<"Invalid Choice"<<endl;
}
}
name="Text_greater_then_15_character";
float temp_data=-1;
switch(temp_ch)
{
case 1:
while(name.length()>15)
{
cout<<" Enter new name:";
cin>>name;
if(name.length()>15)
{
cout<<" Name should be less then 15 character ";
}
}
_name[index]=name;
break;
case 2:
while(name.length()>15)
{
cout<<" Enter new Resturent name:";
cin>>name;
if(name.length()>15)
{
cout<<" Resturent Name should be less then 15 character ";
}
}
_restaurant[index]=name;
break;
case 3:
while(temp_data<0)
{
cout<<" Enter new Value:";
cin>>temp_data;
if(temp_data<0)
{
cout<<" Value should be greater then 0 ";
}
}
_value[index]=temp_data;
break;
case 4:
while(temp_data<0)
{
cout<<" Enter new Pade-to-date:";
cin>>temp_data;
if(temp_data<0)
{
cout<<" Pade-to-date Value should be greater then 0 ";
}
}
_pade_to_date[index]=temp_data;
break;
}
return 1;
}
else
{
cout<<" No record found ";
return 0;
}
}
int search_data(string _name[],string _restaurant[],float _value[],float _pade_to_date[],int count)
{
int flag=0;
float value;
cout<<"Enter value to search the required fields:";
cin>>value;
for(int i=0;i<count;i++)
{
if(_value[i]>=value)
{
flag=1;
cout<<" Record "<<i+1<<":"<<_value[i]<<endl;
}
}
return flag;
}
int display_data(string _name[],string _restaurant[],float _value[],float _pade_to_date[],int count)
{
float sum=0;
for(int i=0;i<count;i++)
{
sum+=_value[i];
cout<<" Record "<<i+1<<":"<<_name[i]<<" "<<_restaurant[i]<<" "<<_value[i]<<" "<<_pade_to_date[i]<<endl;
}
cout<<" Total:"<<sum<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.