coding

profileElm20o
AssignmentDescription43.docx

Assignment #6

Problem Solving and Programming in C++

Department of Computer Science

Old Dominion University

Objectives: The testing process consumes large amounts of data. Creating test data is a crucial part of the testing process especially for new systems which are not in use yet. This assignment will give you an opportunity to practice how to create large amounts of randomly generated test data given parameters.

General Instructions: Read the problem description below and implement this program in C++.

0. You will create three output files

0. The data you will create will be stored in three different txt files

0. Randomly create the data based on the given parameters and specifications.

0. You do not have to submit the txt files with your program. They will be deleted before the graders test your program.

Problem Description: An online retailer is in the process of redesigning its user interface, amidst an expansion into new categories of items (clothing, electronics, etc). The company had been exclusively selling books until now, and thus there is a lack of data to test the interface. You have been tasked with generating random items that have the following attributes:

0. int ID

0. string name

0. string category

0. double price

0. bool two_day_shipping

0. int numclicked

You need to create three separate datasets for testing purposes, each with 1000 items, and store them to a .txt file. Before outputting the generated items to a file, the first 50 items must be displayed to the screen in order to determine whether the random item generator works properly. Then, the user must be prompted to insert the name of the output .txt file.

Item Generation:

ID: each entry should have a unique integer.

Category: only the following strings represent valid categories: (Electronics, Clothing, footwear, books, appliances, apps)

Price: The price depends on the category

Category

Minimum Price

Maximum Price

Electronics

35

1500

Clothing

45

550

Footwear

99

399

Books

7

45

Appliances

150

600

Apps

0.5

4.99

Two Day Shipping: Randomly assign 0 or 1, regardless of category or price

Name: Randomly choose each character. Number of characters in name ranges from 5 to 10

Number of times clicked: Random integer in range (0,10000)

Prior to printing a dataset to a file, display the following characteristics.

Number of items with number of clicks in the following ranges: 0-1000, 1000-2000, 2000-3000, …, 9000-10,000.

Print all columns of most popular item. Item popularity is measured by number of clicks.

Hint: Random data is created using the rand() function available. You can use the modulus operator (%) after rand, followed by a number that represents max, the compiler will output an integer larger than 0 and less than max. Your code will look like int x = rand() % 5; which will give you either 0, 1, 2, 3, or 4. In order to make the output of the rand function really random, we need to set the seed to null. The rand function is basically a counter that constantly counts from 0 to max and depending on when it’s called, it returns the integer. That is why it isn’t very useful for large max numbers. If you output 5 rand numbers that range between 0 and 100 in one function, you will get increasing numbers. In order to be able to set the seed to null, you need to add the following to the beginning of the main function once:

srand (time(NULL));

Task

5. Create dataset of 1000 entries

5. Print first 50 items to screen

5. Output statistics on entire dataset

5. Prompt for filename

5. Output dataset to file

5. Repeat steps 1-5, to create two additional datasets

You also need to include a couple libraries so the compiler knows the srand, time and rand functions:

#include <stdlib.h> //for rand

#include <time.h> //for time

Submission notes:

· Using global variables will result in -10 points off of your final mark.

Figure 1. Samples

Figure 2 Statistics