Huwebes, Marso 5, 2009

ES26: Term-end Machine Problems

ES26: Introduction to Computer Programming
Machine Problem Set    

For all your programs, please provide COMPLETE documentation. I will no longer ask for printed documents, but make sure your program’s code is formatted well.  Deductions will be made for programs that are not neat (meaning hard to read).  Comments embedded in your code will help you lots.

Sorted Linear Regression (with search capability) - sortedLR.c (score: 25 pts)
Create a program that first clears your screen and presents a menu to the user.  The menu should ask if the user wants to (a) read a data file that follows the prescribed format shown below and then sort the data depending on either co-dependent variable (x or y); (b) read a data file that follows the prescribed format and then identify whether a particular value of x appears in the ordered pairs (search linear); or (c) create a data file that follows the prescribed format based on input to be keyed in by the user.

If the user selected the first option, the program should ask for the filename and then ask whether the data will be sorted by x or by y values and whether the sort should be ascending or descending.  After doing so, the program must display the results ON SCREEN in increments of 16 (16 ordered pairs at a time) then the user is given a choice whether to display the next few.  After displaying the ordered pairs, the regression formula is displayed.

If the user selected the second option, the program should ask for the filename and then ask for a value of x.  The program should check for ALL the values in x that match the one given by the user and all the matching y values.  After that, the program should then display the y value if the regression formula were to be used on the value given by the user.

Finally, if the user selected the third option, the program will ask the number of ordered pairs to be saved onto the file, keep asking for values in the ordered pairs, and then save it to a filename specified by the user.

File format: the first line will ALWAYS contain the number of ordered pairs saved in the file.  It is no longer a fixed amount of 30.  However, a restriction for this value will be helpful.  Limit the possible value of the number of ordered pairs to 200.

200
80    127.02
49    212.21
170    -121.04
157    -85.58
53    200.83
37    244.94
25    277.98

74    140.19
93    87.02
34    251.88    Number of lines
x1    y1
x2    y2
x3    y3
x4    y4
x5    y5
x6    y6
x7    y7

x198    y198
x199    y199
x200    y200
Do not worry about having two numbers on one line.  The code from before should be able to read THAT part of the file.


Mob Wars Helper simulator - mobwars.c (score: 80 pts)
Write a program that reads and/or writes to several data files to be able to help you gather crucial information for playing Mob Wars on Facebook.

What data do you need to read/store from/to the data files?
    Properties that can be bought in the city (props.dat)
•    Property number (an integer)
•    Property name (a string)
•    Cost of a property (use an unsigned int because this will possibly reach billions)
•    Required property (an integer)
►    0 if the property does not require anything to be bought
►    otherwise, the property number of the requirement
•    Income for a property (an integer)
    Items that can be bought for your stockpile (items.dat)
•    Item number (an integer)
•    Item name (a string)
•    Cost of an item (an integer)
•    Required item (an integer)
►    0 if the property does not require anything to be bought
►    otherwise, the item number of the requirement
•    Attack bonus of an item
•    Defense bonus of an item
•    Upkeep of the item (an integer) - this is the maintenance cost for each item
    Amount of each property that the user owns (city.dat)
    Amount of each item that the user owns (items.dat)
    User information (user.dat)
•    User type (a character)
►    Tycoon (T)
►    Bulletproof (B)
►    Insomniac (I)
•    Boss name (a string)
•    Amount of money the user has on hand
•    Amount of money the user has in the bank

What information do you need to generate?
    Current inflated cost of a property (an unsigned int)
•    Inflation in Mob Wars means an item is more expensive as you have more of it
•    Think of it as diminishing returns
•    Formula is a tenth of the base cost (cost to buy one when you don’t have any yet) multiplied by the number of the items you own added to the base cost
•      where   is the base cost and   is the number of items owned
    Aggregate cost of a property (an unsigned int)
•    This is the sum of the cost of the property and the sum of the costs of all the requirements
•    For the sake of simplicity, each property only has one requirement
    Return of investment (ROI) for each property (a double or a float)
•    You can represent this in two ways, but both being a result of division of the aggregate cost of the property and its income (or vice versa)
    Hourly income
    Hourly upkeep
    Net hourly income

When the program first runs, it should already be able to initialize all your data elements.  That means all the files have been read and the data represented/stored in your data structures.

Display the user information and create a menu that asks the user what he wants to do from the following:
01    List all properties
02    List all items
03    Buy (a) new propert(y/ies)
04    Buy (a) new item(s)
05    Deposit money to the bank
06    Withdraw money from the bank
07    Exit

When the properties are listed, display the names of the property and cost on one line, the requirement property and aggregate cost on the next, and ROI and the number of this item you can buy on the third line.  (The number of items one can buy in one go is at most 10.)  For example:
Casino (Cost: 40000000)
Needs: Downtown Square; Aggregate cost: 41000000
ROI: 1.804; Able to buy 10

Ask the user if he/she wants to display the properties in a different order or to return to the main menu.  Possible arrangements for the properties are by ROI, Cost, or alphabetically.

When the items are listed, display the items and their properties in groups of 10.  Ask the user after each batch whether to proceed to list the next 10, sort the items in a different manner, or go back to the main menu.

When you buy a new property, the user may buy up to a maximum of ten items in one purchase.  The maximum is implemented, because the inflation rate does not take effect on the individual properties.  The amount that the user has should be decreased and the number of the property owned should be increased in the appropriate data files.

When you buy a new item, the user does not have a maximum number that he/she may buy.  Just make sure that the user has enough money on hand to be able to make the purchase.

When depositing money to the bank, the bank will charge a 10% storage fee to the amount being stored.  Withdrawing the money does not incur any such penalty.  The maintaining balance at the bank is a constant 10000 USD.  The minimum deposit is 2000 USD and the minimum withdrawal is 2000 USD.

For extra 10 points: Insert a new menu item to allow the users to modify the database of items and properties.  Mob Wars is an evolving game and is rebalanced occasionally.  Whenever the game needs rebalancing, some changes are made to the costs of items, jobs, and properties.  Sometimes, even new items, jobs, and properties are introduced.  Make your program flexible that it could write to props.dat or items.dat and update the database.


Bonus program (for fun)
Murphy’s Law - murphy.c, changem.c, murphy.dat (score: 15 pts)
Write two programs that depend on the file murphy.dat.  The first program should be able to generate a random Murphy’s Law stored inside murphy.dat.  The second program should allow the user to delete one of the laws stored in the file or add a new one.  Your separator token should be “~~” for uniformity and so it will run okay during the demo.


Please keep visiting the project page on Multiply and feel free to discuss and collaborate there.  Questions may be posted there that may be answered by other students or other persons who visit my site or even myself!  The files for problem number 2 (Mob Wars Helper simulator) will be placed there and wait for working versions of all programs (in EXE format).  For problem number 3 (Murphy’s Law), look for your own laws.  There are a whole lot of them on the Web.  Have fun creating the programs and remember to be creative.

Attachment: LRfile.txt
Attachment: Machine Problem Set.pdf

9 (na) komento:

  1. sir, wala bang corresponding y value yung 200 sa LRfile.txt?

    TumugonBurahin
  2. Hey... major moment here... the file LRfile.txt was not uploaded in its entirety. Only 35 pairs of values are there. Please change the first line of the file to 35.

    TumugonBurahin
  3. The regression formula, based on LRfile.txt if you change the first line to 35 is...
    y = -2.764797x + 346.314177

    TumugonBurahin
  4. sir wala po ba extension? :D yung mob wars po nagsisimula pa lang ako matuto..huhuhu

    TumugonBurahin
  5. sir, yan po talaga ung regression formula? :| iba sakin. oh noes.

    TumugonBurahin
  6. San i-send ung mga files sir? Sa gmail nyo? Ung edgeangeles@gmail.com"

    TumugonBurahin
  7. sir di ba pwedeng iextend yung deadline?. T~T -ruth

    TumugonBurahin
  8. The files for problem number 2 (Mob Wars Helper simulator) will be placed there and wait for working versions of all programs (in EXE format). Sir ano po ibig sabihin nyan? are u going to let us see the output. given the exe file? ngtatanong lang po...

    TumugonBurahin