Problem Set Data Structure (1) C++ concepts, Lists, and Algorithms, Abstract Data Types @Solvedondemand

of 26
458 views
PDF
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Document Description
As promised, answers almost all questions exploring techniques C++ concepts, Lists, and Algorithms, & made public (not sold). A host of Questions for half a semester on programming strategies for handling data etc... for C++ college course Contact Author subhrodipsengupta@gmail.com +91910634954 (india, Mobile) (+1)2132339492-- LA Office.(EPBAX) If you have any Queries, Solution Requests, Suggestions Of any kind, also for smarter TA's. Or Goodies! At thescintilla we help people develop skills @Copyright (Left, with due credits) Subhrodip Sengupta 22/02 India Thanks to Authors Frank M. Carrano Jannet J Prichard for their lovely book Walls and Mirrors..... C++ This book is still widely used by Instructors in West and India alike. And also to an unknown instructor for formulating some questions.
Document Share
Document Tags
Document Transcript
  Group 1 1. The price of an item you want to buy is given in dollars and cents. You pay for it in cash by giving the clerk d dollars and c cents. Write specifications for a function that computes the change, if any, that you should receive. Include a statement of purpose, the preconditions and post conditions, and a description of the arguments. Ans. Statement of purpose: A C++ function that accepts the total Price in Dollars and cents and payment in cash, and returns a change Precondition: Call to this function passed with a non-void Price in correct sequence (Dollars, cents), non-void argument of user change(Dollars, Cents),iostream should be there to define cout and cerr. Post-Condition: The Output passed by this function, is displayed correctly. The code specification is below: int function(int pd, int pc, int dd, int dc){ if (pd+pc) if((pd+pc)>(dd+dc)) float change = pd+pc/100-dd-dc/100; int changedoll =float(change); float changecent= 100* (change  – changedoll) else cout<< insufficient balance <<endl; bill.changedisplay(“Change is &changedoll dollars, &changecent cents”)  bill.change(&changedoll, &changecent); else cerr<< Goods cannot be free ; return(1); }   3. Write a pseudo code function in terms of the ADT appointment book, described in Section 1.4.1, for each of the following tasks. Do you need to add operations to the ADT to perform these tasks? a. Change the purpose of the appointment at a given date and time. b. Display all the appointments for a given date. ChangeAppointmentPurpose(AB, Date, Time, Purpose, Success) if(AB.IsAppointment(Date, Time)) AB.CancelAppointment(Date, Time, Success) AB.MakeAppointment(Date, Time, NewPurpose, Success) DisplayAllAppointments(AB, Date, Success) Time = Bday while(Time < EndDay) if(AB.IsAppointment(Date, Time)) AB.DisplayAppointment(Date, Time, Success) Time = Time + HalfDay This implementation requires the definition of a new operation, DisplayAppointment(), as well as definitions for the constants Bday, EndDay and HalfDay.  4. Imagine that you have just left a store with a bag of groceries. You are concerned that the fragile items will not survive the trip home, so when you reach your car, you place those items into their own bag. If Bag is a class of bags, write C++ statements that remove all the items from storeBag and place them into one of two new bags, as follows: Place all occurrences of bread and eggs into fragileBag, and all other items into groceryBag. When you are done, storeBag should be empty. Assume that grocery items are represented by strings. Void bag::sort(char *items){ std::string token = s.substr(0, s.find( “ “ )); pos=0; while (token!= items){ If ( token==”bread”)||   (token== “eggs”){   bag.assign( “FragileBag”, &pos) /*assigns serial number of item into fragilebag*/  } else bag.assign(“Grocerybag”, &pos)  ++pos; std::string token = s.substr(pos), s.find( “ “ )); } bag.delete(storebag);//calls a method of class storebag (whose friend our method is). Most compilers would not support delete <object> } 5. Suppose that a bag contains strings that represent various grocery items. Write a C++ function that removes and counts all occurrences of a given string from such a bag. Your function should return this number. Use comments in javadoc style to fully specify your function. Accommodate the possibility that the given bag is either empty or does not contain any occurrences of the given string. Group 2 4. Given two integers, start and end , where end is greater than start , write a recursive C++ function that returns the sum of the integers from start through end , inclusive.   /*In real lyf we have formulae*/ int troll(int pd,int pc){ if (pd!=pc){ pd=2*pd+1; troll(pd,pc); } else{ return(pd); } } 8. Given an integer n> 0, write a recursive C++ function that returns the sum of the squares of 1 through n int troll(int pd,int pc){ if (pd^2!=pc^2){ /*thats right, reusability is why we have included pow here)*/ pd=pd+pd^2; troll(pd,pc); } else{ return(pd); } } #18 only below
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x