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

Orientations Design, edit, compile, and execute a C++ application that gives a m

ID: 3666994 • Letter: O

Question


Orientations

Design, edit, compile, and execute a C++ application that gives a menu with three options:

Create a sequential data file has the information about the items of store. The information will be item description (should be its name), quantity, and price.

Read an existing data file with the information of the items of the store (item description, quantity, and price). In this option, the user can enter a quantity by keyboard and the program will shows the list of items quantity is less than a given one.

Exit

The application must contemplate handling exceptions with the data files used. For example, create a data file that exists, open a data file that does not exist, and others

Give the user the option to enter the name of the data file.

Create a data file with a minimum of 10 items.

Rubrics

In order to obtain all credits (15 points) in this project:

The application must execute correctly (no compilation and execution errors).

The application must have all requirement defined above.

The application must be developed in C++ programming language.

The students must submit all sources files created (files with extension .cpp).

The student must submit the project files on time. Late submissions will be penalized with the loss of points.

Rubrics

In order to obtain all credits (15 points) in this project:

The application must execute correctly (no compilation and execution errors).

The application must have all requirement defined above.

The application must be developed in C++ programming language.

The students must submit all sources files created (files with extension .cpp).

The student must submit the project files on time. Late submissions will be penalized with the loss of points.

Explanation / Answer

/**C++ program that prompts user to enter the quantity from user.
Then print the items of which the quantity is less than the use enter
quanity will be displayed on console.*/

#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
//Set size as constant
#define SIZE 10
//Structure Item
struct Item
{
   char description[40];
   int quantity;
   double price ;

}items[SIZE];;

//function prototype
void showItems(Item *items,int inputQuantity);
int main()
{

   //Create an instance of ifstream
   ifstream fin;
   int inputQuantity=0;
   int index=0;

   //Open file
   fin.open("input.txt");

   //Check if the file exists
   if(!fin)
   {
       //print the error message
       cerr<<"File not found"<<endl;
       system("pause");
       exit(0);
   }

  

   while(fin>>items[index].description>>items[index].quantity>>items[index].price)
   {
       index++;
   }

  
   cout<<"Enter quantity to list the items less than the quantity "<<endl;
   //read
   cin>>inputQuantity;  
   //Call showItems
   showItems(items,inputQuantity);
   //pause the program output on console
   system("pause");
   return 0;
}

/*
The method that showItems an structure pointer and searchQuantity as input arguments
displays the items description, quantity and price of quantity less than searchQunatity.
*/
void showItems(Item *items, int searchQuantity)
{
   for(int index=0;index<SIZE;index++)
   {
       if((items+index)->quantity<searchQuantity)
       {
           cout<<items[index].description<<" "
           <<items[index].quantity<<" "
           <<items[index].price<<endl;
       }
   }
}

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