Please help me with this!!! data.h: /* * Stacks Assignment * Do not modify this comment * * DO NOT MODIFY THIS FILE

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Please help me with this!!! data.h: /* * Stacks Assignment * Do not modify this comment * * DO NOT MODIFY THIS FILE

Post by answerhappygod »

Please help me with this!!!
Please Help Me With This Data H Stacks Assignment Do Not Modify This Comment Do Not Modify This File 1
Please Help Me With This Data H Stacks Assignment Do Not Modify This Comment Do Not Modify This File 1 (36.74 KiB) Viewed 16 times
Please Help Me With This Data H Stacks Assignment Do Not Modify This Comment Do Not Modify This File 2
Please Help Me With This Data H Stacks Assignment Do Not Modify This Comment Do Not Modify This File 2 (159.16 KiB) Viewed 16 times
Please Help Me With This Data H Stacks Assignment Do Not Modify This Comment Do Not Modify This File 3
Please Help Me With This Data H Stacks Assignment Do Not Modify This Comment Do Not Modify This File 3 (29.13 KiB) Viewed 16 times
data.h:
/* * Stacks Assignment * Do not modify this comment * * DO NOT MODIFY THIS FILE */
#ifndef STACKS_DATA_H#define STACKS_DATA_H
#include <string>using std::string;
/* * Simple data structure to simulate the idea of an ADT whichcontains * an identifier and some kind of data. It's not important howcomplex * or simple this structure is, we only want to simulate theidea of * a single simple structure that contains both an identifierand data. */struct Data { int id; string information;};
#endif /* STACKS_DATA_H */
functions.cpp:
/* * Your comment header here * modify this file as needed to complete the assignment */
#include "functions.h"
void rand_string(std::string *str){ // create size 0 to MAXSTRSIZE-1 int rnum = rand() % MAXSTRSIZE;
// make buffer to hold rand string char *buffer = new char[rnum+1];
// fill buffer with random characters A to Z int i = 0; for(; i < rnum; i++){ buffer = (rand() % ('Z' - 'A' + 1))+ 'A'; } buffer = '\0';
// transfer buffer to passed in string *str = buffer;
// clean up delete buffer; return;}
functions.h:
/* * Your comment header here * modify this file as needed to complete the assignment */
#ifndef STACKS_FUNCTIONS_H#define STACKS_FUNCTIONS_H
#define MAXSTRSIZE 8
#include <stdlib.h> /* srand, rand */#include <time.h> /* time */#include <time.h> /* time */#include <string> /* string */
void rand_string(std::string*);
#endif /* STACKS_FUNCTIONS_H */
main.cpp:
/* * your header here * */
#include "main.h"
int main(int argc, char **argv) { // here for the rand_string() function // if you don't use it, get rid of this srand(time(NULL));
/**************************************************************** * First get your arguments from the commandline. Your program must * accept one and only one argument notincluding the program name * itself. That argument must be an integerbetween 2 and any * number (i.e. >= 2). If anything else isentered in any way, * terminate the program with a suitable errormessage telling the * user how to use your program correctly. * * Remember, you may not use more than onereturn, even in main() * and you may not use exit() or anything likethat. ****************************************************************/
/**************************************************************** * Use the number passed in from the commandline and declare a stack * that uses that number as the size of thestack. NOTE: Make sure * your stack ALSO checks the number passed into it. You cannot rely * on main checking the number first, each partof every program and * ADT is always responsible for it's own errorchecking. Main must * check the user gave it a good number. Thestack must check main() * gave it a good number. This is proper errorchecking, no part of * any program can assume it's caller isbehaving correctly. To do this, * try passing -1 or 0 or some other "bad"number to the stack from * main and make sure your stack rejects it, ordefaults to some * pre-defined default value. This will betested during grading. ****************************************************************/
/**************************************************************** * Throughly test your stack. You must performan exhaustive series * of tests on your stack. Show all possibleways your stack can be used * and abused and prove that your stack cangracefully handle ALL cases. * You must use automated testing (no userinput). First cover all * explicit cases which you can think of, thenexecute random operations. * When generating test data, use random intsfor ids and random short * strings for string. There is a stringgenerator made for you in the * functions module. You are free to use it ormake your own. ****************************************************************/
/**************************************************************** * Below is some sample code for the randomstring function. It's * only here to demonstrate the function. DELETEit once you study * it and understand it and can use it yourselfin your code. ****************************************************************/
// make 20 random strings, store them, displaythem std::string strtemp; for(int i=0; i<20; i++){ rand_string(&strtemp); std::cout << strtemp <<std::endl; }
/**************************************************************** * Your code will be tested by applying yourstack to a custom main * designed to break your code. If it can bebroken, you risk a * substantially reduced grade, up to andincluding a zero. ****************************************************************/
// WHEN YOU SUBMIT, DELETE ALL INSTRUCTIONALCOMMENTS!
return 0;}
main.h:
/* * your header here * */
#ifndef STACKS_MAIN_H#define STACKS_MAIN_H
// you probably need all these,// but if you don't get rid of what you don't need#include <stdlib.h> /* srand, rand */#include <time.h> /* time */#include <iostream> /* cout, endl */#include <string> /* string */#include "functions.h"
/* * additional directives here * */
#endif /* STACKS_MAIN_H */
stack.cpp:
/* * Your comment header here * modify this file as needed to complete the assignment */
// each cpp includes ONLY it's header directly#include "stack.h"
/* * write all your stack methods here */
stack.h:
/* * Your comment header here * modify this file as needed to complete the assignment */
#ifndef STACK_H#define STACK_H
/* * there are no other includes here because they are notneeded. * if you do need other things included, they would gohere */
#include "data.h"
class Stack {
public:
/* * write all your public method prototypeshere * this includes you constructor anddestructor */
private:
/* * write all your private method prototypeshere */
// these are the only attributes you need. // do not modify them or add any otherattributes int top; int size; Data **stack;};
#endif //STACK_H
Please follow the assignment's instructions!! Give a validoutput(show a terminal that ran the code please.)
Coding 04: Stacks Description: In this assignment you will create a stack object that will work with a struct data type called Data. The struct data type contains an int called id and a string called information. The stack class will contain all the attributes and methods to have a complete working and proper stack that will work with the struct Data type. You must implement a stack per the definition of a stack as given in class and the stack introduction assignment. Your stack will be capable of being created as any size from 2 to any number based on a parameter passed in from the command line. Your stack will be an array of pointers to Data structs (i.e. not the structs themselves).
Algorithms: • push: The process for pushing to the stack: o Pass data → pass only an int id and string pointer to the stack. Note that a string is an ADT itself so it must be passed by reference. The prototype for push should be one of the following, whichever notation and calls you prefer to use: ■ bool push(int, string&); ■bool push(int, string*); o If there is room in the stack: ■ o o Test the validity of the data (positive int and non-empty string). Do not proceed to push if the data is invalid, return false. ■ Dynamically create a struct Data to hold the data. ■ Put the id and string in the struct Data. ■ Increment the stack counter. ■ Push the pointer for the struct onto the stack. Return true. If there is not room in the stack, return false. Remember, only one actual return statement per function. Algorithms are not written like code, they are written to be logically consistent. The algorithm above looks like there are two or three returns, but in the actual code there should be only one return statement. pop: The process for popping from the stack. o Pass an 'empty' struct Data to the stack (by reference). Note that this means main will have a struct declared and it is passed by reference to the stack so the stack can fill it. This avoids a costly return by value from pop. Make sure you understand this technique well, it is common in programming. o If the stack is not empty... ■ Get the data from the top of the stack and put it in the struct Data passed from the caller. Delete the allocated memory from the top of the stack. ■ ■ Decrement the stack counter. ■ "Return" the data to the caller. Note that you will not actually "return" the data. The act of placing the data in the struct Data passed from the caller is the "return." Return true (notice this pop is different from the last assignment, now it returns a bool).
o If the stack is empty Fill the passed struct with -1 and "" (empty string). • Return false (notice this pop is different from the last assignment, it returns a bool). peek: The process for peek() is the same as pop() but do not deallocate or decrement the counter. Make your peek identical to pop() but simply don't decrement the counter. • isEmpty: The process for isEmpty() is to return true or false based on the top being -1 or not. This can be done in one very simple line of code. Think about it and see if you can do it in one line. You don't have to make it one line, but it's something to think about to improve your code.
Requirements: Remember ONE AND ONLY ONE return per function. If you need more than one, your code is not structured properly. You are given all the files you need for the assignment except .gitignore. Make a proper .gitignore first and commit it. o data.h: Do not modify this file but you should study it. o functions.cpp and functions.h: Modify these as needed. You shouldn't need to, but are free to use this for your own functions and/or to modify the function that is there. main.h and main.cpp: Modify these as needed. Follow the comment instructions in main.cpp. stack.h: Modify this file as needed except for the attributes, do not modify or add to them. stack.cpp: This is essentially blank, it's up to you to fill this in with the correct stack code. o README.md: Modify this file to describe your work. Place your comment headers on all files where indicated. Write a complete and proper stack in stack.cpp/h conforming to the traditional stack definition given above in the algorithms section and as explained in class, following all best practices and loose coupling. o o o • When your program runs, the user must pass in the size of the stack from the command line. For example, a.out 5 or a.exe 10. Your program (main) must check the program is called correctly with one and only one parameter which is an int. If the program is not called correctly, main() must exit gracefully by telling the user they must enter a single parameter at the command line which represents an int for the stack size. Your program must account for every possible user error and handle them accordingly (try everything!). Your stack must be able to be any size from 2 to n where n is any positive integer. Remember when you structure main() you may have only one return statement and may not use any functions that abruptly end the program (for example exit(); ). Make sure you properly allocate and deallocate memory, including deallocating whatever is left in the stack when it exits (i.e. use your destructor to do final clean up). Write complete and exhaustive tests for your stack in main.cpp. o DO NOT use user interaction to test your code. Your main() should be an automated test program demonstrating your stack is robust and fully functional. o Do proper reporting back to the user demonstrating your stack is working and being tested. You must report back from main to the user proving your stack works. o Because your stack can be any size, you must write automated tests that account for this. For example, if the user passes 3 for the stack size, you should be doing on the order of dozens of tests. If the user passes 10, then hundreds of tests. if the user passes 100, then thousands of tests. This means your testing must be dynamic and account for the stack size.
Do not allocate memory for the structs outside the stack. The stack push() method accepts a positive int and a non-empty string, test those to make sure they are valid (positive and non-empty respectively), then creates the struct with that data and pushes the pointer to the struct to the stack. Do not deallocate memory for the struct outside the stack. The stack pop() method retrieves an "empty" struct, and "returns" the data, and then deallocates the stack's internally allocated memory. • All submission and good practice guidelines apply. •
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply