Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can anyone help me on this please? this is urgent task to do on visual c++ 2022. thank you so much what is that? tou

can anyone help me on this please? this is urgent task to do on visual c++ 2022. thank you so much image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
what is that? tou repeat the question
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Here is a CH class definition for an abstract data type Set of strings, representing the concept of ar collection of strings, without duplicates. (A web server might record unicue visitors to a wobsite using a set of strings, for example.) To make thisgs simpler for you, the case of lettens in a string mattern, so thai ibe strings loti and rati are not sonsidered duplicates: chass Set. publie! Sot(), If Create an eavity set (1.e., one whose sire() is 0 ). bool eepty(); If Hetum true if the set is eepty, otheruise false. int sire ( ). If heturn the nuober of itias in the set. bool insert (const itafs string : value): li. Insert value into thin ant if it is not already present, teturn. If true if the velui [ Ctinily inserted. teave the set unchanged If and petarn false. In nut inserted (perhaps because it If was already fo we the cuise the set has a fixed capacity and (I) is ( allil). hool arase(coes stweribring yelue )1 If Benove the valun frim thin wet if it is aresent. Return true if the (1. value was renoved; vitheroise, leave the set unchanged and ff retien taliow. bool contains(const statimtrines value)s If Return trie if the value is in the set, etherwise false. bool git (int To stadistrings value), If If a 6 is sire(). cony into value the iten in the set that is 1). strictly greater than exactly i item in the set and return true. if otherilse, leave value unchanged and return false. void map(seth other); If twahange the contents of this sut with the other one. j. When we don't want a function to change a parameter representing a value of the type stored in the set, wo pais that parameter by conatant reference. Passing is by valoe would have been perfectly fine for this problern, bat we chose the const reference alternative hocause that will be more suitable after we make some generalizations in a later problem] Notice that the comment for the cet fusetion implies that for a 5 -item set ss, ws get (6,x) will copy the smallest ifem in the set into x (because the smallest items is greater than 0 . items in the set), and isinet (4,x) will copy the largest item (because the largest itern is greater than 4 ifems in the set). The words greaker thap, smallerf, ete., are all interpreted in tae context of what the s operator for string indicates aboat the relative order of two strings: Notice that the enpty string is just as good a string as any other, you should not treat it in any special way! Set isp 4. inserit("dosa") assert\{losicontains (=4)). asidnsert(" tartilla")s Th. incert (=) in os insert('-focarcia ) oviart(csicontaino () w. eraivi(-idosa"), strine assert(kget (1,v) as y= "foracelan) abiert(csiget (6,v) s4 v7) Nobce that the empty string is just as good a striag as any other: you should not treat it in any ipecial way; When conyparing items for intert, erase, contalnis, and get, just use the m,1=,3, etc., operators provided for the string typo by the library; The and thart fine. Here is what you are to do: 1. Determine which member fiurtion aceordingly. 2. As defined above, the Scr class allowins the client to use a set that contains ouly stal astrings. Somseone who wanted to modify the class to contait items of another iype, such as ealy ints or only doub les, would have to make changes in many places. Modify the class definition you produced in the previoris problern to uwe a type alias for all values wherever the oniginal definition used a stdicatring. A bye allas is a name that is a synonym for some type; here is an example: Wh the following tine introduces thin typen allas Muiber as a synoeyn If for the type int; anyatiere the code wses the nate Hueber, it means ff the type int. The advantage of wing the type alias Number is that if we later wish to modify this code to sum a sequence of lergs or of dkubles, we need make a change in only one place the using statemeat iatroducing the type alias Number. To make the grader's life easieg, well require that everyone use the same synonym for their type alias: You must use the name stewlypt, with exactly that speling and ease. 3. Now that you have defined an interface for in set class where the isens type can be easily changed, iniplement the class and all its member funclions in awch a way that the items in a set are cootained in a data member that is an array. (Notice we faid an array, oot a pointer, It's not until problem 5 of this homevorie that you'lt deal with is dyaarnically allocated array) A set mast be able to hold a maximum of oer hut. r. pax. trens items, where \[ \text { const int Deraurt rax_17E55 * } 160 \text { i } \] Test your class for a Set of ataf istrings. Phace your class definition and inline function implementations (if aay) in a file named Set . h, and your nane-intine fincehor which is fise.) You may add whatever private data raembers and private iaciober fuactions you like, and yos may declare pravare structs clarses innifs Yocr implemenimiton of the set clats must be soch that the compiler-geneeated destractoc, copy constrictoc, and assiggament opecator do the right thiagk Write a teat progenam muned testset eppis to make sure your Set ctass implementation works properly. Here is one possible (iscomplete) test propram: Now change (only) the type alias in set.h so that the Set will contain unsigned Ionger. Make ne other changer to set, he, and make no changes fo Set, eqp. Yerify itat your implementation builds correctly and works properly with this alternatice nain routine (which again, is not a complete tent of cocrectasss): the type alias in 5 .t. in a witing statemeat introwycing a type alias, the words unsigned and long must pot appear in set, b or Set, ceve. (Implernentation note. The ranp fusction is easily implementable without ereating any additional contaiber of many items such as an additional artay of an additineal Set.) 4. Now that you've implemeated the class, write some clieat code that uses it. A librarian might want a class that kecps track of the library card auribers of all patrons who eheck items out of the library. A patron might check out few or many items few or masy times, but the card number should be included caly coce. (The Ebrarizn just wants to be able to know which cards are actually being used, not how many times they're used.) Implement the following elass that uses a Set of unsinned laras: Alinc lude 5et,h class Cardset 1 publict Cardset (). If create an eapty card sot. bool add (unsinged lone carditumber). II Add a card nuober to the Cardset. Heturn true if and anly if the W card nuitier was actually added. int size() const; If Return the number of card mabers in the Cardset. publice Carisiet (9): 1/ create an eapty card sat. trool add (unsigned Inot - carallimber): If Ad a card nueber to the Cardiet. Return true if and only if the 11 card number was actually added. Int size() const; If Return the munber of card nuabers in the Carilset. quid pirint() const, (f irite to ceoit every card nueber in the Cardset exactly once, one If per life. Write no other text. lerivate: If soes of your sode gees here. You Candset implenamiation unust employ a data metaber of type Set that uses the type alias it in Type as a syookym for untily Ser, not of type poinin I aniit a laember of type Cariset class, Natine of Cardset, b, Cardset, opp, and testcardiet. epp: Cardset's meinber fanctione nvist not call Set tridapi 5. Now that youve created a set type based on amayn whose size is fixed at corpple time. lufs change the implemeatation to use a dymankalhy aliocafed array of objects. Copy modifying your existing constructor lo that a clien can do the following: Set a(10e0) i = cin hild at most 16ed distince ithes Set b(5). (f h cen hold at most 3 dieftinct itens Itralype v6] - ( sor alistinct wives of the appropriate type ). If lis falluret inserting 5 distinct itees inte b fen ( int k=e,k,e,j,ku) issert (b. imaret {y[k])}. publict. ariset (P). 8 Create an enoty card sat. ff asd a card nueber to the cardiet. Retarn true if and only if thei ff card nuwber yas actually addedi. Int sire(?) const: ff Return the nurber af card nunbers in the cardset. Qutid purint ( ) consti. If writi co coat every card nukber in the Cardset exactly once, phe If per line. Mrite no other text. Mrivatel. ff sides of your code geess hince. Set, not of type poin . Ficept for the using starement introctucing the typo alias, you imust not make any changes to the " Cardsec's merabor finctions naust not call sett idung. modifying your existing constractor so that a client can do the follorvise: Set a(10e0) i ff acen hald at nost 1000 distinct items Set b(5). . . hi can hold at most 5 distinct ifeas Set cj ff cican hold at most o4 Furt Max 1rMS distinct iteas tromypev 6}={sixafistinctvoluesoftheappropriotetype)2 Sf Ho fad lures inserting 5 dist int t itees inte t fer (int k=0;k operator for string indicates about the relative order of two strings: Here's an example of the swap function: Notice that the empty string is just as good a string as any other; you should not treat it in any special way: Set 8s; ss. insert ("dosa"); assert (1ss. contains ())/3 ss.insert ("tortilla"); ss. insert(" = ) ; Bs.insert (" focaceia") assert (ss, contains ()j) 35. erase( "dosa"): string vy ss. contains ()) i assert (ss, get (1,v) Gi v= "focaceia* ); assert(ss.get (0,v) it v=N= When comparing items for insert, erase, contains, and get, just use the =m,I=,>, etc. operators provided for the string type by the library. These do case-sensitive comparisons, and thar's fine. Here is what you are to do: 1. Determine which member functions of the Set class should be const member functions (because they do not modify the Set), and change the class declaration accordingly. 2. As defined above, the Set class allows the client to use a set that contains only stds a strings. Someone who wanted to modify the class to contain items of another type, such as only ints or only doubles, would have to make changes in many places. Modify the class definition you produced in the previous problem to use a type alias for all values wherever the original definition used a stdrustring. A type alias is a name that is a synomym for some type; here is an example: // The following line introduces the type alias Nt 1/ for the type int; anywhere the code uses the ni II the type int. using Number = int ; int main() f Number total =0; Number x; while (cinmx) total in i cout total endl; 3 The advantage of using the type alias Number is that if we later wish to modify this code to sum a sequence of longs or of doubles, we need make a change in only one place: the using statement introducing the type alias Number. (Aside: Prior to C++11 (and still usable now), the only way to introduce a type alias was to use a typedef statement, egg. typedef int Number: Appendix A.1.8 of the textbook describes typedef,) To make the grader's life easier, we'll require that everyone use the same synonym for their type alias: You must use the name I temType, with exactly that spelling and case. Now that you have defined an interface for a set class where the item type can be easily changed, implement the class and all its member functions in such a way that the items in a set are contained in a data member that is an array. (Notice we said an array, not a pointer. It's not until problem 5 of this homework that you'll deal with a dynamically allocated array.) A set must be able to hold a maximum of DEFAULT_MAX_ITEMS items, where const int DEFAULT_MAX_ITEMS =160; Test your class for a Set of std; : strings. Place your class definition and inline function implementations (if any) in a file named set. h, and your non-inline function implementations (if any) in a file named Set.cep. (If we haven't yet discussed inline, then if you haven't encountered the topic yourself, all your functions will be non-inline, which is fine.) Except to add a dump function (described below), you must not add public data or function members to, delete functions from, or change the public interface of the Set class. You may add whatever private data members and private member functions you like, and you may declare private structs/classes inside the Set class if you like. If you wish, you may add a public member function with the signature void dunp() const. The intent of this function is that for your own testing purposes, you can call it to print information about the set; we will never call it. You do not have to add this function if you don't want to, but if you do add it, it must not make any changes to the set; if we were to replace your implementation of this function with one that simply returned immediately, your code must still work correctly. The dump function must not write to cout, but it's allowed to write to cerr. Your implementation of the Set class must be such that the compilergenerated destructor, copy constructor, and assignment operator do the right things. Write a test program named testSet. epp to make sure your Set class implementation works properly. Here is one possible (incomplete) test program: Now change (only) the type alias in Set . h so that the Set will contain unsigned longs. Make no other changes to Set. h, and make no and works properly with this alternative main routine (which again, is not a complete test of correctness): You may need to flip back and forth a few times to fix your Set. h and Set. cpp code so that the only change to those files you'd need to make to change a set's item type is to the type alias in Set, h. (When you turn in the project, have the type alias in Set. h specify the item type to be std astring.) Except in a using statement in set. h introducing a type alias and in the context of whelude " class Cardset fublie: CardSet(); bool add(unsigned long cardNumber); // Add a card number to the Cardset. Return tru // card number was actually added. int size() const; // Return the number of card nu void print () const; // Write to cout every card number in the Cardse (/ per 1 ne. Write no other text. private: // Some of your eode goes here. Your CardSet implementation must employ a data member of type Set that uses the type alias Iteatype as a synonym for unsigned long. Your CardSet implementation must employ a data member of type Set that uses the type alias ItemType as a synonym for unsigned long. (Notice we said a member of type Set, not of type pointer to Set.) Except for the using statement introducing the type alias, you must not make any changes to the set. h and set. cpp files you produced for Problem 3, so you must not add any member functions or data members to the Set class. Each of the member functions add, size, and print must delegate as much of the work that they need to do as they can to Set member functions. (In other words, they must not do work themselves that they can have Set member functions do instead.) If the compiler-generated destructor, copy constructor, and assignment operator for CardSet don't do the right thing, declare and implement them. Write a program to test your CardSet class. Name your files Cardset.h, Cardset. opp, and testcardset.cpp. The words for and while must not appear in Cardset. h or Cardset.epp, except in the implementation of cardset: apr int if you wish. The characters [ (open square bracket) and * must not appear in cardset.h or cardset. epp, except in comments if you wish. You do not have to change unsigned long to ItemType in Cardset. h and cardset. epp if you don't want to (since unlike Set, which is designed for a wide variety of item types, CardSet is specifically designed to work with unsigned longs). In the code you tum in, Cardset's member functions must not call Set: : dump. Now that you've created a set type based on arrays whose size is fixed at compile time, let's change the implementation to use a dynamically allocated array of objects. Copy the three files you produced for problem 3 , naming the new files newset. h, newset. cpp, and testnewset. cpp. Update those files by cither adding another constructor or modifying your existing constructor so that a client can do the following: Since the compiler-generated destructor, copy constructor, and assignment operator no longer do the right thing, declare them (as public members) and implement them. Make no other changes to the public interface of your class. (You are free to make changes to the private members and to the implementations of the member functions, and you may add or remove private members.) Change the implementation of the swap function so that the number of statement executions when swapping two sets is the same no matter how many items are in the sets. (You would not satisfy this requirement if, for example, your swap function caused a loop to visit each item in the sets, since the number of statements executed by all the iterations of the loop would depend on the number of items in the sets.) The character [ (open square bracket) must not appear in newset.h (but is fine in newset. cpp). Test your new implementation of the Set class. (Notice that even though the file is named newset. h, the name of the class defined therein must still be set.) Verify that your CardSet class still works properly with this new version of Set (with Itemtype being a type alias for unsigned long). You should not need to change your CardSet class or its implementation in any way, other than to \#include "newset. . " instead of "Set. . . (For this test, be sure to link with new5et. cpp, not Set. cpp.) (Before you turn in cardset . h, be sure to restore any = ineludes to "Set. h " instead of "newset. h) Turn it in By Monday, January 23, there will be a link on the class webpage that will enable you to turn in this homework. Turn in one zip file that contains your solutions to the homework problems, (Since problem 3 builds on problems 1 and 2, you will not turn in separate code for problems 1 and 2.) If you solve every problem, the zip file you turn in will have nine files (three for each of problems 3,4 , and 5 ). The files must meet these requirements, or your score on this homework will be severely reduced: - Each of the header files Set. .h, Cardset.h, and nevset. h mast have an appropriate include guard. In the files you tum in, the using statements in Set, h and newset. h must introduce Iteniype as a type alias for stdinstring. - If we create a project consisting of Set.h, Set.cpp, and testset. cpp, it must build successfully under both g 32 and either Visual C++ or clang ++. (Note: To build an executable using g32 from some, but not all, of the ecpp files in a directory, you list the cpp files to use in the command. To build an executable named req1 for this requirement, for example, you'd say g32=0 req1 set.cpp testset.cpp.) - If in Set, h we change I temType to be a type alias for unsigned long, and then create a project consisting of Set. h, Set. cpp, CardSet. h, CardSet.cpp, and testcardset.cpp, it must build successfully under both g 32 and either Visual C++ or clangt+. - If we create a project consisting of newset, h, newset. epp, and testnewset. cepp, it must build successfully under both g32 and cither Visual C++ or clang +. - If we create a project consisting of nevset. h, newset. cpp, and testSet. cpp, where in testSet. cpp we change only the ginelude "Set. h " to ennelude "newSet. h ", the project must build successfully under both g 32 and cither Visual C++ or elang+t. (If you try this, be sure to change the \#include back to "Set. h " before you turn in testset.,epp.) - The sourve files you submit for this homework must not contain the word friend or pragma of vector, and must not contain any global variables whose values may be changed during execution. (Global constants are fine.) - No files other than those whose names begin with test may contain code that reads anything from cin or writes anything to cout, except that for problem 4, cardset: : print must write to cout, and for problem 5 , the implementation of the constructor that takes an integer parameter may write a message and exit the program if the integer is negative. Any file may write to cerr (perhaps for debugging purposes); we will ignore any output written to cerr. - You must have an implementation for every member function of Set and CardSet. If you can't get a function implemented correctly, its implementation must at least build successfully. For example, if you don't have time to correctly implement Set: ; serase or Set ; ; swap, say, here are implementations that meet this requirement in that they at least allow programs to build successfully even though they might execute incorrectly: bool Set; serase(const ItemTypes value) f return true; // not correct, but at least t \} void Setirswap(sets other) f // does nothing; not correct, but at least \} - Given Set, h with the type alias for the Set's item type specifying stdr rstring, if we make no change to your set. cpp, then if we compile your set.cpp and link it to a file containing the linking must succeed. When the resulting executable is run, it must write Passed all tests and nothing more to cout and terminate normally. - If we suecessfully do the above and then in Set. h change the type alias for the Set's item type to specify unsigned long as the item type without making any other changes, recompile set, cpp, and link it to at file containing \#include "Set, h " \#include using namespace std; file containing the linking must succeed. When the resulting executable is ran, it must write Passed al1 tests and nothing more to cout and terminate normally. - Given newset. n with the type alias for the Ser's item type specifying. std a s string, if we make no change to your newset. cpp, then if we compile your newset. cpp and link it to a file containing. the linking must suceeed. When the resalting executable is run, it must write Passed all tests and nothing more to cout and terminate normally. - If we successfully do the above and then in nesset. th change the type alias for the Set's item type to specify unsigned long as the item type without making any other changes, recompile nevset . epp, and link it to a file containing Hinelude "newset. h" Ainclude \#include using namespace std; void test() f int main() f test(): cout \&e "Passed all tests" \&e endl; h the linking must succeed. When the resulting executable is run, it must write Passed all tests and nothing more to cout and terminate normally. - If we successfully do the above and then in newSet. h change the type alias for the Set's item type to specify unsigned long as the item type without making any other changes, recompile newset. cpp, and link it to a file containing the linking must succeed. When the resulting exceutable is run, it must write Passed a11 tests and nothing more to cout and terminate normally. - During execution, your program must not perform any undefined actions, such as accessing an array element out of bounds, or dereferencing a null or uninitialized pointer. - In each source file you tum in, do not comment out your implementation: you want our test scripts to see it! (Some people do this when testing other files' code because they put all their code in one project instead of having a separate project for each of problems 3, 4. and 5 , of alternatively, having one project and removing (without deleting!) some files from the project and adding them back and removing others to test various combinations of files.) Notice that we are not requiring any particular content in testset.cpp, testcardset, cpp, and testnewset, cpp, as long as thcy mest the requirements above. Of course, the intention is that you'd use those files for the test code that you'd write to convince yourself that your implementations are correct. Although we will throughly evaluate your implementations for correctness, for homeworks, unlike for projects, we will not grade the thoroughness of your test cases. Incidentally, for homeworks, unlike for projects, we will also not grade any program commenting you might do

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions