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

INTRODUCTION The goal of this project is to enable the student to implement a si

ID: 3742746 • Letter: I

Question

INTRODUCTION

The goal of this project is to enable the student to implement a simple C++ program whose code is broken into three source files. At the same time, the student utilizes standard C++ libraries.

HIGH LEVEL SPECIFICATION

Write a program that first asks for the number of items to be ID stamped. The program then loops as many times as the number that was input. For each loop pass, the program asks for a description and generates a unique integer to be the identifier of the item. The program then displays a message stating that the unique identifier for the given product it the generated number.

REQUIRED LIBRARIES

Library name Purpose iostream contains definitions of cin, cout, endl, and input/output operators cstdlib contains rand( ) and srand( ) for random number generation string contains definition of type string chrono contains definitions of time functions Other you may include other libraries as needed for additional functionality you wish to add.

DATA STRUCTURE

Write a C++ class called ID_stamp that you will save in a file called ID_stamp.h which has the following:

Private data members:

• variable named stamp of type integer

•variable name desc of type string for product description

Public function members:

These functions should be declared in the class and defined outside the class.

• Input data function that has no parameters and returns nothing. The function should display a message prompting for input of a description string. It should then read keyboard input of a string (you may use getline( ) ). Your program then extracts the current time using now( ) function of chrono. This is passed to the rand( ) function to generate an integer that will be considered the unique identifier assigned to stamp.

• Display data function that outputs both the entered string and the stamp to the screen with description and formatting added.

Definitions of the member functions should be saved in a file called ID_stamp.cpp

PROCESSING

Write a main() function that instantiates (declares) an object of type ID_stamp. Next, a prompt of number of items to stamp is displayed followed by reading an integer.

A loop is then entered that runs as many times as the integer just read and does the following:

• call the input data function

• call the display data function

The main() function and all code associated with it should be saved in a file called ID_stamp_driver.cpp

ADDITIONAL REQUIREMENTS

The program should meet the following requirements:

• variable names should be meaningful. Avoid single letter variable names

• there should be comments at the following points (a) beginning to describe the main purpose of the program (b) before every function to describe task, parameters, return values, preconditions, and postconditions (c) to explain important variables (d) at important points such as input, outputs, loops and ifs

DOCUMENTATION

Write a report using word processing software with the following format: Four sections with the following headings respectively: (a) Problem definition (b) Analysis (c) Design (d) Test data and implementation

The analysis section should explain choices of libraries, variables, formulas (if any), and reasons for the choices. In other words, this section answers the what question.

The design section should give pseudocode of all functions used in the program. Pseudocode must be structured such that statements inside a function should be indented right and statements inside loops and ifs should be indented further right. Pseudocode should be in English phrases NOT C++. Structural design may also be presented such as class design. This section presents how your program solves the problem presented to you.

The implementation section should give other programmers who read the document an idea of how you made the program work. You should describe the platform (operating system and compiler) that you used.

Explanation / Answer

ID_stamp_driver.cpp

#include "ID_stamp.h"

// runs program
int main(){
// instantiates the object firstStamp from the class ID_stamp
ID_stamp firstStamp;

cout << "having fun with git!";
}


ID_stamp.cpp

#include "ID_stamp.h"


// Definitions of the member functions should be saved in a file called ID_stamp.cpp
// prompts user for itemAmount and bootstraps the program.
ID_stamp::ID_stamp(){
// user prompt for stamps
cout << " How many items will be ID stamped? ";

// fetches amount of stamps
cin >> stampAmount;

// Data validation
// repeat the following as long as this attempt failed,
// presumably because the data type of the user's input was not of type int
while (! cin.good() || stampAmount < 1 || stampAmount > 2147483647) {

    // re-enable the just-disabled cin object
    cin.clear();

    // from the input buffer,
    //discard up to 80 keystrokes or
    // until the enter key is seen, whichever comes first
    cin.ignore(80, ' ');

    // tell the user what happened, and to try again
    cout << "Invalid type, should be within 1 and 2147483647, try again: ";

    // attempt to get an input value whose data type is an integer
    //
    // the boolalpha manipulator is used
    // in case integers are bools, to allow
    //for inputs using the keystroke
    // sequences of "true" and "false" instead of "1" and "0"
    cin >> boolalpha >> stampAmount;
}

// bootstraps the rest of the program
forEachStampAmount(stampAmount);
}

// Loops through program for the amount of stamps the user selected
void ID_stamp::forEachStampAmount(int stampAmount){
for (int i = 0; i < stampAmount; i++){
    inputData(i + 1);
    setDescription();
    setStampID();
    displayData();
}
}

// Input data function that has no parameters and returns nothing. The function should display a
// message prompting for input of a description string.
void ID_stamp::inputData(int i){
cout << " Input a description for stamp #" << i << endl;
}

// sets description of the stamp, reads keyboard input of a string (you may use getline( ) ).
void ID_stamp::setDescription(){
// ignores linebreaks and everything that would enterfere with getline
cin.ignore();
getline(cin, desc);
}

// sets unique ID of the stamp, Your program then extracts the current time using now( )
// function of chrono. This is passed to the rand( ) function to generate an integer that will be
// considered the unique identifier assigned to stamp.
void ID_stamp::setStampID(){
// Creates a time object
auto current_time = chrono::system_clock::now();
// gets time since epoch from current time
auto duration = current_time.time_since_epoch();
// converts that time to milliseconds
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();

// Seed for random, prevents program from using the same # continuously
srand(millis);

// assigns a random number to stamp
stamp = rand() % millis + 1;
}

// Display data function that outputs both the entered string and the stamp to the screen with
// description and formatting added.
void ID_stamp::displayData(){
getDescription();
getStampID();
}

// displays stamp description
void ID_stamp::getDescription(){
cout << " The description is: " << desc << endl;
}

// displays stamp unique ID
void ID_stamp::getStampID(){
cout << " The stamp ID is: " << stamp << endl;
}


ID_stamp.h


// contains definitions of cin, cout, endl, and input/output operators
#include <iostream>
// contains rand( ) and srand( ) for random number generation
#include <cstdlib>
// contains definition of type string
#include <string>
// contains definitions of time functions
#include <chrono>

//standard namespace
using namespace std;

/*******************************************************************************

                              Class prototype

*******************************************************************************/
class ID_stamp
{
// class members that cannot be accessed directly
private:
    // storage for items to be stamped
    int stampAmount;
    // variable named stamp of type integer
    int stamp;
    // variable name desc of type string for product description
    string desc;
// class members that can be used freely within the class
public:
    // prompts user for itemAmount and bootstraps the program.
    ID_stamp();
    // Loops through program
    void forEachStampAmount(int itemAmount);
    // Input data function that has no parameters and returns nothing. The function should display a
    // message prompting for input of a description string.
    void inputData(int i);
    // sets description of the stamp, reads keyboard input of a string (you may use getline( ) ).
    void setDescription();
    // sets unique ID of the stamp, Your program then extracts the current time using now( )
    // function of chrono. This is passed to the rand( ) function to generate an integer that will be
    // considered the unique identifier assigned to stamp.
    void setStampID();
    // Display data function that outputs both the entered string and the stamp to the screen with
    // description and formatting added.
    void displayData();
    // displays stamp description
    void getDescription();
    // displays stamp unique ID
    void getStampID();
};

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