The Demetris Leadership Center publishes the books, DVDs, and CDs listed in the following table:

Title: Description Product Number Unit Unit Sold
Brave New World Book 110 25.50 925
Lady Gaga CD 111 16.00 275
The Forgotten DVD 112 24.50 289
Twilight DVD 113 45.50 135
The Giving Tree Book 114 24.50 540
Lil Wayne CD 115 35.50 234

The manager of the telemarketing group has asked you to write a program that will help order-entry operators to look up product prices. The program should prompt the user to enter a product number, and then will display the title, description, and the price of the product.

The program should use the following functions:

main - the program's main function
readinfo- read data from the file and store them in arrays
getprodnum- prompts the user to enter a product number. the function validates input and rejects any value outside the range of correct product numbers. Display the title, description and a price of the product.

calcsales- calculates each product's sales. calculate the total sales for all units.

binsearch- searches the array of product's sales for a specified value. if the value is found, its subscript is returned. if the value is not found, -1 is returned.

selsort- sort the list of the products in the order of their sales dollars, not units sold, from highest to lowest.

This is what i have so far:

#include <iostream>

#include <conio.h>

using namespace std;

struct Shop


        int Price;

        int Amount;


void PrintPrice (Shop Product);

void PrintAmount (Shop Product);

int main()


that's all i know how to do and I'm not even sure if it is correct!

Another good ol' database program. This calls for 'an array of structs'

create your data type:

struct record
     string description;
     int product_number;
     double unit;
     int sold;

Now that you have designed your object, you need to create a bunch of them:

record database[100];

One of your menu options should provide a function to populate your objects... whenever the user wishes to add to the database:


     cout << "Enter product description: ";
     cin >> database[i].description;

     cout << "Enter product number:  ";
     cin >> database[i].product_number;
     etc. etc.


}while(another == 'y' || another == 'Y');

You also have the ability to search your array of structs:

//this will return the element position of the found record in database (if not found, return -1)
int find_by_sales(record database[], int sold_target, int entries_made)
     int i=0;

     while(database[i].sold != sold_target && i <= entries_made)

     if(i == entries_made)

          return -1;


          return i;

You can have similar functions to perform sorting as well, where you can sort the database[] array based on a single attribute.

Here is an easy way to sort the database[] array based on a single attribute (in this case, we'll use sales) using the sort() function from <algorithm>


bool sales_test(record& i,  record& j){return (i.sold < j.sold);}

sort(&database[0], &database[entries], sales_test);

You can also have a menu option that will display the entire database contents:

void display_database(record database[], int entries_made)
     for(int i=0; i<entries_made; i++)
          cout << "\nProduct description:  " << database[i].decription;
          cout << "\nProduct number:  " << database[i].product_number;
          cout << "\nUnit Number:  " << database[i].unit;
          cout << "\nQuantity Sold:  " << database[i].sold;
          cout << endl << endl << end;

So that's it. Another typical database program. Whether it be bank accounts, phonebook, airline tickets, hotel reservations, or in this case, point of sale... it's all just a matter of creating a struct, then creating an array of structs. Populate, manipulate, sort, search, and display.

p.s. you'll probably be doing this several.. several.. several.. times during your cs academic career, so it is good to get down with this concept asap.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.