Archive

Posts Tagged ‘otherwise’

On Monthly Salary

January 30th, 2010 Comments off

Hi Bidders,

Our company requires a blog comment poster.

Work type:
Just write 30-40 words relevant post and submit on blogs – we’ll provide the URLs, in actual your job is to write good and on topic.

Time Demand:
we’ll need daily 4hrs at least.

Salary:
interested to pay $100 per month but if you think isn’t fair then you are free to put your option (though I am sure for asians its enough good).

Confirmation of bid:
You’ll be on trial for a week, if passed then we’ll move for longer ocntract otherwise you’ll be paid for a week and we’ll end the work with you to explore better option.

Note:
* Must send a sample with your bid otherwise bid will be ignored.

** Any Q then feel free to ask but before placing your bid – come on PMB and discuss, if bid placed first and Qs asked later then consider yourself out.

*** Put “Feb2010″ in your bids and msgs otherwise you’ll not be ocnsidered.

Best of Luck ~

Collection Classes

June 14th, 2009 Comments off

I am looking for help with an Assignment I am working on. Let me know if you can help.

Problem Description:

Create a DOS console application that keeps track of a list of names. Your program should be able to add a name, remove a name at the current position, to concatenate two name lists, to retrieve a name from the list, and to print out the whole list of names in the list.

Implementation requirement:

You are going to use two classes to implement this assignment: TestStringArraySeq, StringArraySeq. The TestStringArraySeq is the application driver class and contains the main() method. The StringArraySeq is the worker class. You have to use sequence collection data structure to implement this worker class. The storage data structure for the collection class should be array. In this class, you need to implement the following methods:

StringArraySeq
public StringArraySeq ()
This constructor takes no argument. It initializes the instance variable manyItems to 0; initializes the instance variable currentIndex to 0, and allocates 10 cells for the arrary data.

StringArraySeq
public StringArraySeq (int initialCapacity)
This constructor takes one argument. It first checks to see whether the parameter is positive. If it is negative, the an exception is thrown. It then initializes the instance variable manyItems to 0; initializes the instance variable currentIndex to 0, and allocates initialCapacity number of cells for arrary data.

getManyItems
public int getManyItems ()
This simple method returns the value of instance variable manyItems. Setters and getters are used to enforce information hiding.

setManyItems
public void setManyItems (int m)
This simple method sets the instance variable manyItems to the value passed in.

getCurrentIndex
public int getCurrentIndex ()
This simple method returns the value of instance variable currentIndex.

setCurrentIndex
public void setCurrentIndex (int c)
This simple method sets the instance variable currentIndex to the value passed in.

addAfter
public void addAfter(String element)
addAfter places a new element after the current element. If there is no current element, then the addAfter method places the new element at the end of the sequence. In all cases, when the method finishes, the new element will be the current element.

start
public void start()
this sequence help method sets the current element at the front of the sequence.

isCurrent
public boolean isCurrent()
this is an accessor method used to determine whether this sequence has a current element. It should be called before calling the method getCurrent.

ensureCapacity
public void ensureCapacity(int minimumCapacity)
this help method changes the capacity of the sequence to the minimumCapacity. This method is only needed if the sequence is implemented using array.

toString
public String toString()
This method returns all a String with the names in the sequence class. Each name appears on a separate line.

getCurrent
public String getCurrent()
this is an accessor method used to retrieve the value of current element.

advance
public void advance()
this sequence help method moves forward so that the current element is now the next element in the sequence. Before calling this method, you should call isCurrent() method to make sure that there is a current element. If the current element is the last element, then after calling this method there will be no current element. Otherwise, the new element is the element immediately after the original current element.

removeCurrent
public void removeCurrent()
removeCurrent removes the current element from a sequence. Before invoking this method, you should call isCurrent() to make sure that there is a current element. When this method is called, if the current element is the final element, then after the removal there is no longer a current element; otherwise, the new current element is the one that used to be after the removed element.

concatenation
public static StringArraySeq concatenation(StringArraySeq s1, StringArraySeq s2)
concatenation method creates a new sequence that contains all the elements from the first sequence followed by another. The resulting sequence has no current element. The concatenation is somewhat similar to the union of two bags. This method is implemented with static method. As a general rule, the methods that operate on two collections are usually implemented as static methods. This is because of the reason that static methods are able to handle parameters that are null.

clone
public Object clone()
the clone method returns a copy of this sequence. The return object should have separate memory space. Subsequent changes to the copy will not affect the original, nor vice versa. The return value should be typecast to a StringArraySeq before it is used. Since the current element is not specified, you can set currentIndex of the returned object to any value.

getString
public static String getString(StringArraySeq s, String target)
This method returns the first occurrence of the target string in the sequence class. If there is not such a string, the method returns null. To implement this method, you must use the following methods: start(), isCurrent(), advance(), and getCurrent(). If the target is fund, you should set the currentIndex to the position where the target is; do nothing to the currentIndex otherwise.
Note: you can learn how regular methods use static methods from this.

removeString
public boolean removeString(String target)
This method removes the target string from the sequence class if it exists (first occurrence). The method returns true when the operation is successful and returns false if the operation fails. If the removal is successful, the following element is set to be the current element. If there was no following element, then there is now no current element.
Note: suggest to use getString(), removeCurrent() methods.

You can reference all the methods in the bag collection class and the supplement note 3. Most of the methods of the bag class and of the sequence class are almost identical, but you need to be careful for those that are different.
I suggest you to use the following class instance variables for the sequence class:
data

Categories: Java Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Flash-based Video Poker Game

May 21st, 2009 Comments off

We would like to have a Flash-based “Video Poker” game built which our customers can play for free, but have it attached to a list of our informational products on gambling awareness which they can download after paying for them via PayPal or shopping cart.

The video poker game must adhere to all the strict coding concerns of a real, play-for-money video poker game. For example, all random number generation for dealing cards must happen at the server, every credit played must register in the database before a result is given to the client, no memory-resident info or game code can be on the client side that might be exploited to compromise the security of the game, etc. Although the game will be played for free, there will be a lot of prestige tied to winning and we will spend a lot of money promoting it so it is important that the game is secure and that the logic is true to every aspect of a normal video poker game based on standard probability and a regular deck of cards. In short, our informational products are based on the likelihood that almost *all* gamblers lose, and we trade in informational products to promote that notion, so we need the game authentic with perfect odds. We can’t have people win (or lose) more than they’re normally “supposed to.” One of the products we will be selling is the cumulative results of all players playing this play-for-free video poker, so the playability must be perfectly inline with mathematical expectations of the same machine sitting on a casino floor. The reason they can only play after buying one of our products is because we need to limit the number of credits people get, otherwise if you could play 100% for free indefinitely you would do many careless things you wouldn’t otherwise do as a player. Since play “credits” are somewhat limited, there is more prestige in people “winning prizes” which are just awards they can print on their local printer which have the name of some reward like “steak dinner” or “penthouse suite”.

The game must have a ‘progressive jackpot’ which increments as any player plays, and as all players are sitting in the site they must see this grand jackpot climb in real time, even if they are just sitting idle on the shopping cart page or in the chat lobby. Also, as players sit on the site they must see flashing banners announcing other players’ winnings who are logged on somewhere else in the world, again in real time.

There are two sites you could use to see the playability we are looking for:

Golden Palace dot com – select to play the free, Flash-based version of jacks-or-better video poker.

FreeSlots.com/poker – this is EXACTLY what we want, minus the ancillary features like hints, double pays, etc. Although it is important to note that this version does NOT get its results from the back end, the RNG and all game code resides on the client side which we do NOT want. Otherwise, this site is a perfect example of the look and feel, the sounds, placement of buttons, etc, since it is based off of the original video poker game by IGT. The version we want specifically is the game “8/5 Jacks or Better.”

We would like a couple other ancillary pages such as a login page, edit profile page, etc – no biggie. Please respond to the following questions:

- can you do this work?

- we’re a very cash-poor startup. Can you work ‘cheap’ even if it takes longer to complete? Could you detail what you consider ‘cheap’ either as rate-per-time or a project bid?

- we’ll want to build more games into this site as the first one takes off, what would your ‘less cheap’ rate be to continue development of future enhancements?

- what technologies will you use? We think we prefer Flash, PHP, MySQL but are open to suggestions.

- will we have absolute rights to source code and all necessary components/technologies upon completion?

- where are you located, and if not near Chicago, how do we coordinate & validate development throughout the production process?

Thank you, I look forward to your response.

Article To Be Rewritten Twice

May 4th, 2009 Comments off

These are the specification you need to meet:
Article topic:Information related-car insurance advice

Project Budget:8

Article length: 300-700 words

Minimum of 8 paragraphs. It is better to have lots of small paragraphs than a few big ones, as it makes the resulting articles more unique..

Title on the top line (max length 65 characters), followed by a blank line, and then the first paragraph. The title should contain your keyword phrase.

A blank line between each paragraph.

Paragraphs may be formatted either as fixed-length, or as free-flow text, both formats will work.

Each bullet point or list item should also be separated by a blank line – i.e. each bullet point counts as a new paragraph – otherwise they will end up being concatenated (chained together) and it will no longer look like a list.
The whole article should be in basic ANSII text (i.e. a Notepad file).
Step 2: Re-write the Article Twice
needs to be rewritten twice in the following manner (each of the two versions should be a completely fresh re-write according to these specs):
1. The Title needs to be rewritten, but must still capture or describe the theme of the article in as engaging or interesting way as possible.
2. Each paragraph needs to be reworded. The number of words and sentences in the paragraph may change. The overall content and meaning of the paragraph must remain the same.
3. The number of paragraphs must NOT change. i.e. if the article starts with 8 paragraphs it must end up with 8 paragraphs, and each of those paragraphs should still say the same thing as the original article, but just using different words. Any subheadings that are a single line should be rewritten, and should remain as a single line.
4. If the article has bullet points or lists, then each line of the list should be reworded, but the number of points or lines must remain the same. The style of bullet must remain the same, i.e. if the bullets are asterisks, they should remain asterisks. If the bullet points are numbered, then the numbering must be done in the save format. Each bullet point or list item should also be separated by a blank line – i.e. each bullet point counts as a new paragraph – otherwise they will end up being concatenated and it will no longer look like a list.
5. Articles are to be formatted as follows: Title on top line. Empty line. Paragraph1 followed by empty line, Paragraph2 followed by empty line, etc.
Examples of Articles
Version 1
This is the title of a great article

Your first paragraph goes here. This paragraph will often also appear on its own as a summary/preview of your article. Note that it is written as a single line, followed by a double line break before the next paragraph.

It so happens that this paragraph is actually the start of a list. You don’t have to use a numbered list, but if you do, separate each point by a blank line:

1. point one on your list (these do not have to be numbered points)

2. Point two on your list (but if you do use numbers, make sure you use the same numbering system on all three versions)

3. Point three on your list

Closing paragraph, again all on one long line.
Version 2
Your great article has this title

Then comes a great introduction on a single line, followed by a double line break. This opening paragraph will often also be used as a summary of your article.

And some great points to be made. You might, or might not, do these as numbered points. Either way make sure the points are separated by blank lines:

1. Point one of a great list (which may or may not be numbered)

2. Your next point (remember to always use the same numbering system)

3. A final point
Version 3
What a fantastic title for an article

All you need is a good introduction which can alse serve as a summary for your article, all on one line, then move on to the next paragraph, using a double line break.

So we then introduce your main points. Mostly you will just do this as ordinary paragraphs. But if you choose to do a list (numbered or otherwise) make sure you separate each point with a blank line.

1. A great point here (which does not have to be numbered)

2. Another great point (but do use the same numbering system if you do number them)

3. Yet a third thing to consider

Now sum it all up with your closing paragraph, all on one long line.

Your closing points can be made in a summing up paragraph on one line. And that is how you finish off.

Text Messaging Censoring

April 26th, 2009 Comments off

Objective
To give students practice at writing a program using strings.

The Problem
Many people, after a late night, for whatever reason, tend to send emails or text messages that they shouldn

Categories: C/C++ Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

C Lemonade Stand

April 5th, 2009 Comments off

Here is what needs to be done. I have the skeleton code too which i have included right after the instructions. This program must compile in Dev C++ and it needs to be in the format in the instructions.

Objectives
1. Review use of if statements and loops.
2. Learn how to write functions given specifications.
3. Learn how to use pass by reference variables.
4. Learn how to put together a useful program given a skeleton of that program and the
functions and their specifications necessary in the implementation.

Problem: Lemonade Stand
Last summer your friend has a lemonade stand and made lots of money. You want to do the same! You have plenty of time to plan, so you thought you would be pre
pared when summer came around by writing a program to simulate your lemonade stand. The basic idea behind the simulation is as follows:

1) You will simulate 10 days of running the lemonade stand.
2) In the beginning the user gets a $20.00 loan to run the lemonade stand.
3) Before each day, the user gets an opportunity to buy bags of lemons and sugar.
4) At the beginning of each day the user receive a weather report.
5) Based on that, the user is asked to price a cup of lemonade for that day.
6) Then, the days sales are simulated. (Part of this is written for you.)
7) Afterwards, the user is prompted with a status report of how much money they have left and how many bags of lemons and sugar they have left.

What you have to do
A skeleton of the solution for this assignment is posted on WebCourses and the course web page. Please use this skeleton. You must fill in the seven functions that are left for you to fill in, as well as write the remainder of main so the program works as described above. After you write each function, you should test it before moving on. How to do this will be covered in class. Then, write your main, calling the necessary functions from it to achieve the desired functionality. main can work without declaring any new variables than the ones already declared. But, you may declare new ones if you wish.

Perhaps the biggest problem you will have will be not knowing when to make function calls. The goal of having these functions is to make the coding process more manageable. In particular, it is possible that a function might “do” something complicated, but that just really means that function makes calls to other functions that carry out a majority of that work already. In essence, if you write a function A to do a task, then don’t write out the code that also does that task in another function B. Instead call the function A from the body of function B.

References
Textbook: Chapters 9, 10, 11 Notes: Lectures 13, 14, 15, 17

Output Sample
Two full output samples of the program running will be provided on Webcourses and the course web page in the files lemonade.out and lemonade2.out.

Deliverables
You must submit your solution to the problem, lemonade.c, over WebCourses.

Restrictions
Although you may use other compilers, your program must compile and run using DevC++. Please use DevC++ to develop your program. Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date. Also, make sure you include ample comments throughout your code describing the major steps in solving the problem.

Grading Details
Your program will be graded upon the following criteria:

1) Your correctness
2) Your programming style and use of white space. (Even if you have a plan and your program works perfectly, if your programming style is poor or your use of white space is poor you could get 10% or 15% deducted from your grade.)
3) Compatibility to DevC++. (If your program does not compile in this environment, you will get a sizable deduction from your grade, likely to be over 50%)

The code Skeleton:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// Symbolic constants to be used.

// Prices of bags of sugar and lemon, respectively.
#define PRICE_LEMON 3.50
#define PRICE_SUGAR 2.00

// Fraction of a bag of lemons and sugar used on a single cup of lemonade.
#define LEMON_PER_CUP 0.03
#define SUGAR_PER_CUP 0.04

// The initial loan the user is given to start their lemonade stand.
#define START_MONEY 20.00

// Using symbolic constants for true and false.
#define FALSE 0
#define TRUE 1

void buy_lemons(double *pLemons, double *pMoney);
void buy_sugar(double *pSugar, double *pMoney);
int weather();
int num_cups_sold(int weather, int cost);
void status_report(double cash, double num_lemons, double num_sugar, int day);
int max_sell(double num_lemons, double num_sugar);
int get_cost();
void sell_cups(double *pMoney, double *pLemons, double *pSugar);
void end_message(double money);

int main() {

int num_day, ans;
double money = START_MONEY, num_lemons = 0, num_sugar = 0;

srand(time(0));

printf(“Welcome to the Game of Lemonade!nn”);
printf(“You start the game with $%.2lf and no supplies!n”, START_MONEY);

// Loop through each day. Ask the user if they want to buy lemons. If so,
// carry out the transaction. Then ask them if they want to buy sugar.
// If so, do this transaction as well. Then, let them sell lemonade for
// the day. Finally, print a status report after they’ve sold lemonade
// at the end of the day.
for (num_day = 1; num_day <= 10; num_day++) {

}

// Print out whether or not they have lost money, broke even or gained
// money.

return 0;
}

// Pre-conditions: pLemons and pMoney are pointers to variables that store
// the user’s number of bags of lemons left and amount of
// money left.
// Post-condition: The user is given the opportunity to buy lemons. If
// successful, the number of bags of lemons and the amount
// of money the user has are adjusted accordingly.
//
// What to do in this function: If the user doesn’t have enough money to
// even buy one bag of lemons, tell them so and return. Otherwise, ask
// the user how many bags of lemons they want to buy. If they answer less
// than one, tell them they must get more and reprompt them. If they
// answer more than they can buy, tell them they don’t have that much
// money and reprompt them. Continue prompting them until they answer with
// a valid value. Then process the transaction.

void buy_lemons(double *pLemons, double *pMoney) {

}

// Pre-conditions: pSugar and pMoney are pointers to variables that store
// the user’s number of bags of lemons left and amount of
// money left.
// Post-condition: The user is given the opportunity to buy sugar. If
// successful, the number of bags of sugar and the amount
// of money the user has are adjusted accordingly.
//
// What to do in this function: If the user doesn’t have enough money to
// even buy one bag of sugar, tell them so and return. Otherwise, ask
// the user how many bags of sugar they want to buy. If they answer less
// than one, tell them they must get more and reprompt them. If they
// answer more than they can buy, tell them they don’t have that much
// money and reprompt them. Continue prompting them until they answer with
// a valid value. Then process the transaction.

void buy_sugar(double *pSugar, double *pMoney) {

}

// Pre-condition: None
// Post-condition: The weather report for the day is printed and the
// corresponding weather status in between 1 and 5,
// inclusive, is returned.
int weather() {

// Get the weather status value.
int retval = rand()%5 + 1;

printf(“nHere is today’s weather forecast:n”);

// Print out the appropriate forecast for that status.n”);
if (retval == 1)
printf(“It is cloudy with a high chance of rain.n”);
else if (retval == 2)
printf(“It is partly cloudy and windy.n”);
else if (retval == 3)
printf(“It is partly sunny with low humidity.n”);
else if (retval == 4)
printf(“It is warm and sunny with medium winds.n”);
else
printf(“It’s a perfect beach day. Sunny and hot!n”);

return retval; // Return this status value.
}

// Pre-condition: weather is an integer in between 1 and 5, inclusive,
// standing for the weather status for the day. cost is
// the cost of a cup of lemonade in cents for that day.
// Post-condition: The number of cups of lemonade for that day is returned.
int num_cups_sold(int weather, int cost) {

int optimal_price, max_cups;
double max_income;

// Calculate a maximum revenue for the day.
max_income = 5 + 3*weather;
optimal_price = 15 + 5*weather;
max_income = max_income – fabs(optimal_price – cost)/1.5;

// If it’s lower than 5 dollars, reset it to 5 dollars.
if (max_income < 5)
max_income = 5;

// From this, determine the maximum number of cups that could be sold.
max_cups = (int)(max_income/((double)cost/100));

// Return a random number from 0 to this maximum.
return rand()%(max_cups+1);

}

// Pre-condition: cash is the amount of cash the user has, num_lemons is
// the number of bags of lemons the user has left, num_sugar
// is the number of bags of sugar the user has left, and day
// is which day of the game just finished.
// Post-condition: A status report with the four values passed in is nicely
// displayed for the user.
//
// What to do with this function: This is fairly self-explanatory from the
// pre and post conditions. Look to the sample given in the assignment for
// the format.
void status_report(double cash, double num_lemons, double num_sugar, int day) {

}

// Pre-condition: pMoney, pLemons and pSugar are pointers to the variables
// storing the user’s amount of cash, number of bags of
// lemons and number of bags of sugar.
// Post-condition: A day’s transactions will take place and the amount of
// money, the number of bags of lemons and sugar will be
// adjusted accordingly.
//
// What to do with this function: First prompt the user with the weather
// report. Then, ask the user for how much they want to sell a cup of
// lemonade. Determine the number of cups that actually get sold for the
// day by determining how many cups the user COULD sell based on the
// availability of supplies and how many cups they COULD sell based on the
// weather. Print out how many cups of lemonade they ended up selling.
// Then adjust the amount of money they have, as well as the number of bags
// of lemons and sugar.

void sell_cups(double *pMoney, double *pLemons, double *pSugar) {

}

// Pre-condition: num_lemons is the number of bags of lemons the user has,
// and num_sugar is the number of bags of sugar they have.
// Post-condition: The function returns the maximum number of cups of
// lemonade the user can sell based on available supplies.
//
// What to do with this function: Calculate how many full cups of lemonade
// you can supply with sugar. Do the same calculation for lemons. Then,
// return the smaller of these two values.

int max_sell(double num_lemons, double num_sugar) {

}

// Pre-condition: None.
// Post-condition: Returns the number of cents the user will sell a cup of
// lemonade for, for that day.
//
// What to do with this function: Prompt the user to enter how much they
// want to charge for a cup of lemonade. If they don’t enter a positive
// integer, reprompt them until they do. Then return this value.

int get_cost() {

}

// Pre-condition: money is the amount of money the user has left at the end
// of the 10 days of running their Lemonade Stand.
// Post-condition: The user’s overall loss or profit is printed out.

// What to do with this function: See if what they have left is less than
// what they started with. If so, print out how much the lost. If it’s equal
// just print out a message saying that they broke even. Otherwise, print
// out how much profit they made!

void end_message(double money) {

}

Categories: C/C++ Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Lemonade Stand

April 3rd, 2009 Comments off

Here is what needs to be done. I have the skeleton code too which i have included right after the instructions. This program must compile in Dev C++ and it needs to be in the format in the instructions.

Objectives
1. Review use of if statements and loops.
2. Learn how to write functions given specifications.
3. Learn how to use pass by reference variables.
4. Learn how to put together a useful program given a skeleton of that program and the
functions and their specifications necessary in the implementation.

Problem: Lemonade Stand
Last summer your friend has a lemonade stand and made lots of money. You want to do the same! You have plenty of time to plan, so you thought you would be pre
pared when summer came around by writing a program to simulate your lemonade stand. The basic idea behind the simulation is as follows:

1) You will simulate 10 days of running the lemonade stand.
2) In the beginning the user gets a $20.00 loan to run the lemonade stand.
3) Before each day, the user gets an opportunity to buy bags of lemons and sugar.
4) At the beginning of each day the user receive a weather report.
5) Based on that, the user is asked to price a cup of lemonade for that day.
6) Then, the days sales are simulated. (Part of this is written for you.)
7) Afterwards, the user is prompted with a status report of how much money they have left and how many bags of lemons and sugar they have left.

What you have to do
A skeleton of the solution for this assignment is posted on WebCourses and the course web page. Please use this skeleton. You must fill in the seven functions that are left for you to fill in, as well as write the remainder of main so the program works as described above. After you write each function, you should test it before moving on. How to do this will be covered in class. Then, write your main, calling the necessary functions from it to achieve the desired functionality. main can work without declaring any new variables than the ones already declared. But, you may declare new ones if you wish.

Perhaps the biggest problem you will have will be not knowing when to make function calls. The goal of having these functions is to make the coding process more manageable. In particular, it is possible that a function might “do” something complicated, but that just really means that function makes calls to other functions that carry out a majority of that work already. In essence, if you write a function A to do a task, then don’t write out the code that also does that task in another function B. Instead call the function A from the body of function B.

References
Textbook: Chapters 9, 10, 11 Notes: Lectures 13, 14, 15, 17

Output Sample
Two full output samples of the program running will be provided on Webcourses and the course web page in the files lemonade.out and lemonade2.out.

Deliverables
You must submit your solution to the problem, lemonade.c, over WebCourses.

Restrictions
Although you may use other compilers, your program must compile and run using DevC++. Please use DevC++ to develop your program. Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date. Also, make sure you include ample comments throughout your code describing the major steps in solving the problem.

Grading Details
Your program will be graded upon the following criteria:

1) Your correctness
2) Your programming style and use of white space. (Even if you have a plan and your program works perfectly, if your programming style is poor or your use of white space is poor you could get 10% or 15% deducted from your grade.)
3) Compatibility to DevC++. (If your program does not compile in this environment, you will get a sizable deduction from your grade, likely to be over 50%)

The code Skeleton:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// Symbolic constants to be used.

// Prices of bags of sugar and lemon, respectively.
#define PRICE_LEMON 3.50
#define PRICE_SUGAR 2.00

// Fraction of a bag of lemons and sugar used on a single cup of lemonade.
#define LEMON_PER_CUP 0.03
#define SUGAR_PER_CUP 0.04

// The initial loan the user is given to start their lemonade stand.
#define START_MONEY 20.00

// Using symbolic constants for true and false.
#define FALSE 0
#define TRUE 1

void buy_lemons(double *pLemons, double *pMoney);
void buy_sugar(double *pSugar, double *pMoney);
int weather();
int num_cups_sold(int weather, int cost);
void status_report(double cash, double num_lemons, double num_sugar, int day);
int max_sell(double num_lemons, double num_sugar);
int get_cost();
void sell_cups(double *pMoney, double *pLemons, double *pSugar);
void end_message(double money);

int main() {

int num_day, ans;
double money = START_MONEY, num_lemons = 0, num_sugar = 0;

srand(time(0));

printf(“Welcome to the Game of Lemonade!nn”);
printf(“You start the game with $%.2lf and no supplies!n”, START_MONEY);

// Loop through each day. Ask the user if they want to buy lemons. If so,
// carry out the transaction. Then ask them if they want to buy sugar.
// If so, do this transaction as well. Then, let them sell lemonade for
// the day. Finally, print a status report after they’ve sold lemonade
// at the end of the day.
for (num_day = 1; num_day <= 10; num_day++) {

}

// Print out whether or not they have lost money, broke even or gained
// money.

return 0;
}

// Pre-conditions: pLemons and pMoney are pointers to variables that store
// the user’s number of bags of lemons left and amount of
// money left.
// Post-condition: The user is given the opportunity to buy lemons. If
// successful, the number of bags of lemons and the amount
// of money the user has are adjusted accordingly.
//
// What to do in this function: If the user doesn’t have enough money to
// even buy one bag of lemons, tell them so and return. Otherwise, ask
// the user how many bags of lemons they want to buy. If they answer less
// than one, tell them they must get more and reprompt them. If they
// answer more than they can buy, tell them they don’t have that much
// money and reprompt them. Continue prompting them until they answer with
// a valid value. Then process the transaction.

void buy_lemons(double *pLemons, double *pMoney) {

}

// Pre-conditions: pSugar and pMoney are pointers to variables that store
// the user’s number of bags of lemons left and amount of
// money left.
// Post-condition: The user is given the opportunity to buy sugar. If
// successful, the number of bags of sugar and the amount
// of money the user has are adjusted accordingly.
//
// What to do in this function: If the user doesn’t have enough money to
// even buy one bag of sugar, tell them so and return. Otherwise, ask
// the user how many bags of sugar they want to buy. If they answer less
// than one, tell them they must get more and reprompt them. If they
// answer more than they can buy, tell them they don’t have that much
// money and reprompt them. Continue prompting them until they answer with
// a valid value. Then process the transaction.

void buy_sugar(double *pSugar, double *pMoney) {

}

// Pre-condition: None
// Post-condition: The weather report for the day is printed and the
// corresponding weather status in between 1 and 5,
// inclusive, is returned.
int weather() {

// Get the weather status value.
int retval = rand()%5 + 1;

printf(“nHere is today’s weather forecast:n”);

// Print out the appropriate forecast for that status.n”);
if (retval == 1)
printf(“It is cloudy with a high chance of rain.n”);
else if (retval == 2)
printf(“It is partly cloudy and windy.n”);
else if (retval == 3)
printf(“It is partly sunny with low humidity.n”);
else if (retval == 4)
printf(“It is warm and sunny with medium winds.n”);
else
printf(“It’s a perfect beach day. Sunny and hot!n”);

return retval; // Return this status value.
}

// Pre-condition: weather is an integer in between 1 and 5, inclusive,
// standing for the weather status for the day. cost is
// the cost of a cup of lemonade in cents for that day.
// Post-condition: The number of cups of lemonade for that day is returned.
int num_cups_sold(int weather, int cost) {

int optimal_price, max_cups;
double max_income;

// Calculate a maximum revenue for the day.
max_income = 5 + 3*weather;
optimal_price = 15 + 5*weather;
max_income = max_income – fabs(optimal_price – cost)/1.5;

// If it’s lower than 5 dollars, reset it to 5 dollars.
if (max_income < 5)
max_income = 5;

// From this, determine the maximum number of cups that could be sold.
max_cups = (int)(max_income/((double)cost/100));

// Return a random number from 0 to this maximum.
return rand()%(max_cups+1);

}

// Pre-condition: cash is the amount of cash the user has, num_lemons is
// the number of bags of lemons the user has left, num_sugar
// is the number of bags of sugar the user has left, and day
// is which day of the game just finished.
// Post-condition: A status report with the four values passed in is nicely
// displayed for the user.
//
// What to do with this function: This is fairly self-explanatory from the
// pre and post conditions. Look to the sample given in the assignment for
// the format.
void status_report(double cash, double num_lemons, double num_sugar, int day) {

}

// Pre-condition: pMoney, pLemons and pSugar are pointers to the variables
// storing the user’s amount of cash, number of bags of
// lemons and number of bags of sugar.
// Post-condition: A day’s transactions will take place and the amount of
// money, the number of bags of lemons and sugar will be
// adjusted accordingly.
//
// What to do with this function: First prompt the user with the weather
// report. Then, ask the user for how much they want to sell a cup of
// lemonade. Determine the number of cups that actually get sold for the
// day by determining how many cups the user COULD sell based on the
// availability of supplies and how many cups they COULD sell based on the
// weather. Print out how many cups of lemonade they ended up selling.
// Then adjust the amount of money they have, as well as the number of bags
// of lemons and sugar.

void sell_cups(double *pMoney, double *pLemons, double *pSugar) {

}

// Pre-condition: num_lemons is the number of bags of lemons the user has,
// and num_sugar is the number of bags of sugar they have.
// Post-condition: The function returns the maximum number of cups of
// lemonade the user can sell based on available supplies.
//
// What to do with this function: Calculate how many full cups of lemonade
// you can supply with sugar. Do the same calculation for lemons. Then,
// return the smaller of these two values.

int max_sell(double num_lemons, double num_sugar) {

}

// Pre-condition: None.
// Post-condition: Returns the number of cents the user will sell a cup of
// lemonade for, for that day.
//
// What to do with this function: Prompt the user to enter how much they
// want to charge for a cup of lemonade. If they don’t enter a positive
// integer, reprompt them until they do. Then return this value.

int get_cost() {

}

// Pre-condition: money is the amount of money the user has left at the end
// of the 10 days of running their Lemonade Stand.
// Post-condition: The user’s overall loss or profit is printed out.

// What to do with this function: See if what they have left is less than
// what they started with. If so, print out how much the lost. If it’s equal
// just print out a message saying that they broke even. Otherwise, print
// out how much profit they made!

void end_message(double money) {

}

Categories: C/C++ Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Black Jack C++ Help

April 2nd, 2009 Comments off

Background

For this assignment, you complete a program to play the game of “Twenty-one” (also called “Blackjack”).

The general idea of Twenty-one is as follows. There are two players, the customer and the dealer. The dealer deals a card face down to the customer, then a card face up to herself (the up-card), then another card to the customer and another card to herself, both face down. In most cases, the customer may then ask for more cards, one at a time. The dealer does the same, and the hand is resolved. The object of the game is to be dealt a set of cards whose total value is as close to 21 as possible without going over.

Cards are dealt from a deck of 52. There are four cards in the deck with value 2, four with value 3, and so on up to value 9; there are sixteen cards with value 10 (four 10′s and twelve face cards: four jacks, four queens, and four kings); and there are four cards (“aces”) whose value may be either 1 or 11 depending on the value of a player’s remaining cards. For both players, an ace counts 11 unless the hand total is more than 21, in which case it counts 1.

For our purposes, the actual play of the game proceeds as follows. Each player receives two cards as described above. If the dealer’s cards total 21

Categories: C/C++ Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Bear