### Pythong Modules

#### C4Q6: Mass and Weight

posted Feb 13, 2010, 11:30 PM by muh.adil@gmail.com

 `Program Description:`# ******************************************************************************``# Book Name: Starting Out with C++: Control Structures through Objects,``# Brief Version by Tony Gaddis.``# Chapter Name: Making Decisions``# Author: Adil Muhammad (itsaboutcode)``# Chapter Number: 4``# Challenge Number: 6``# Challenge Name: Mass and Weight``# ******************************************************************************``# Scientists measure an object's mass in kilograms and its weight in Newtons. If``# you know the amount of mass that an object has, you can calculate its weight,``# in Newtons, with the following formula:``#``# Weight = mass * 9.8``#``# Write a program that asks the user to enter an object's mass, and then``# calculates and displays its weight. If the object weighs more than 1,000``# Newtons, display a message indicating that it is too heavy. If the object``# weighs less than 10 Newtons, display a message indicating that the object is``# too light.``# ******************************************************************************`Code:`http://pythonmodules.googlecode.com/svn/trunk/Python/Chapter4/src/C4Q6.py``

#### C4Q5: Test Scores and Grade

posted Feb 13, 2010, 11:28 PM by muh.adil@gmail.com

 `Program Description:`# ******************************************************************************``# Book Name: Starting Out with C++: Control Structures through Objects,``# Brief Version by Tony Gaddis.``# Chapter Name: Making Decisions``# Author: Adil Muhammad (itsaboutcode)``# Chapter Number: 4``# Challenge Number: 5``# Challenge Name: Test Scores and Grade``# ******************************************************************************``# Write a program that has variables to hold three test scores. The program``# should ask the user to enter three test scores and then assign the values``# entered to the variables. The program should display the average of the test``# scores and the letter grade that is assigned for the test score average. Use``# the grading scheme in the following table.``#``# Test Score Average Letter Grade``# ----------------- ------------``# 90 or greater A``# 80-89 B``# 70-79 C``# 60-69 D``# Below 60 F``# ******************************************************************************`Code:`http://pythonmodules.googlecode.com/svn/trunk/Python/Chapter4/src/C4Q5.py``

#### C6Q6: Kinetic Energy

posted Feb 8, 2010, 11:52 PM by muh.adil@gmail.com

 `Program Description:`# ******************************************************************************``# Book Name: Starting Out with C++: Control Structures through Objects,``# Brief Version by Tony Gaddis.``# Chapter Name: Making Decisions``# Author: Adil Muhammad (itsaboutcode)``# Chapter Number: 6``# Challenge Number: 6``# Challenge Name: Kinetic Energy``# ******************************************************************************``# In physics, an object that is in motion is said to have kinetic energy. The``# following formula can be used to determine a moving object's kinetic energy:``#``# KE = 1/V mv^2``#``# The variables in the formula are as follows: KE is the kinetic energy, m is the``# object's mass in kilograms, and v is the object's velocity, in meters per second.``#``# Write a function named kineticEnergy that accepts an object's mass (in kilograms)``# and velocity (in meters per second) as arguments. The function should return``# the amount of kinetic energy that the object has. Demonstrate the function by``# calling it in a program that asks the user to enter values for mass and velocity.``# ******************************************************************************`Program Code:`http://pythonmodules.googlecode.com/svn/trunk/Python/Chapter6/src/C6Q6.py``

#### C6Q7: Celsius Temperature Table

posted Feb 3, 2010, 9:16 AM by muh.adil@gmail.com   [ updated Feb 8, 2010, 11:53 PM ]

 `Program Description:`# ******************************************************************************``# Book Name: Starting Out with C++: Control Structures through Objects,``# Brief Version by Tony Gaddis.``# Chapter Name: Making Decisions``# Author: Adil Muhammad (itsaboutcode)``# Chapter Number: 6``# Challenge Number: 7``# Challenge Name: Celsius Temperature Table``# ******************************************************************************``# The formula for converting a temperature from Fahrenheit to Celsius is``#``# C = 5/9 ( F - 32)``#``# where F is the Fahrenheit temperature and C is the Celsius temperature. Write``# a function named celsius that accepts a Fahrenheit temperature as an argument.``# The function should return the temperature, converted to Celsius. Demonstrate``# the function by calling it in a loop that displays a table of the Fahrenheit``# temperatures 0 through 20 and their Celsius equivalents.``# ******************************************************************************`Code:`http://pythonmodules.googlecode.com/svn/trunk/Python/Chapter6/src/C6Q7.py``

#### C6Q5: Falling Distance

posted Feb 1, 2010, 7:22 AM by muh.adil@gmail.com

 `Program Description:`# ******************************************************************************``# Book Name: Starting Out with C++: Control Structures through Objects,``# Brief Version by Tony Gaddis.``# Chapter Name: Making Decisions``# Author: Adil Muhammad (itsaboutcode)``# Chapter Number: 6``# Challenge Number: 5``# Challenge Name: Falling Distance``# ******************************************************************************``# When an object is falling because of gravity, the following formula can be used``# to determine the distance the object falls in a specific time period:``#``# d = 1/2 gt^2``#``# The variables in the formula are as follows: d is the distance in meters, g is``# 9.8, and t is the amount of time, in seconds, that the object has been falling.``#``# Write a function named fallingDistance that accepts an object's falling time``# (in seconds) as an argument. The function should return the distance, in meters,``# that the object has fallen during that time interval. Write a program that``# demonstrates the function by calling it in a loop that passes the values 1``# through 10 as arguments, and displays the return value.``# ******************************************************************************`Code:`http://pythonmodules.googlecode.com/svn/trunk/Python/Chapter6/src/C6Q5.py``

#### C6Q4: Safest Driving Area

posted Jan 31, 2010, 1:26 AM by muh.adil@gmail.com

 `Program Description:`# ******************************************************************************``# Book Name: Starting Out with C++: Control Structures through Objects,``# Brief Version by Tony Gaddis.``# Chapter Name: Making Decisions``# Author: Adil Muhammad (itsaboutcode)``# Chapter Number: 6``# Challenge Number: 4``# Challenge Name: Safest Driving Area``# ******************************************************************************``# Write a program that determines which of 5 geographic regions within a major``# city (north, south, east, west, and central) had the fewest reported automobile``# accidents last year. It should have the following two functions, which are``# called by main.``#``# * int getNumAccidents() is passed the name of a region. It asks the user for``# the number of automobile accidents reported in that region during the last year,``# validates the input, then returns it. It should be called once for each city``# region.``#``# * void findLowest() is passed the five accident totals. It determines which is``# the smallest and prints the name of the region, along with its accident figure.``#``# Input Validation: Do not accept an accident number that is less than 0.``# ******************************************************************************`Code:`http://pythonmodules.googlecode.com/svn/trunk/Python/Chapter6/src/C6Q4.py``

#### C3Q24: Stock Transaction Program

posted Jan 30, 2010, 6:36 AM by muh.adil@gmail.com

 `Program Description:`# ******************************************************************************``# Book Name: Starting Out with C++: Control Structures through Objects,``# Brief Version by Tony Gaddis.``# Chapter Name: Expressions and Interactivity``# Chapter Number: 3``# Challenge Number: 24``# Challenge Name: Stock Transaction Program``# ******************************************************************************``# Last month Joe purchased some stock in Acme Software, Inc. Here are the details``# of the purchase:``#``# * The number of shares that Joe purchased was 1,000.``# * When Joe purchased the stock, he paid \$32.87 per share.``# * Joe paid his stock broker a commission that amounted to 2% of the amount he``# paid for the stock. Two weeks later Joe sold the stock.``#``# Here are the details of the sale:``# * The number of shares that Joe sold was 1,000.``# * He sold the stock for \$33.92 per share.``# * He paid his stock broker another commission that amounted to 2% of the amount``# he received for the stock.``#``# Write a program that displays the following information:``# * The amount of money Joe paid for the stock.``# * The amount of commission Joe paid his broker when he bought the stock.``# * The amount that Joe sold the stock for.``# * The amount of commission Joe paid his broker when he sold the stock.``# * Did Joe make money or lose money? Display the amount of profit or loss after``# Joe sold the stock and paid his broker (both times).``# ******************************************************************************`Code:`http://pythonmodules.googlecode.com/svn/trunk/Chapter3/src/C3Q24.py``

#### C3Q25: Word Game

posted Jan 30, 2010, 6:36 AM by muh.adil@gmail.com

 ``# ******************************************************************************``# Book Name: Starting Out with C++: Control Structures through Objects,``# Brief Version by Tony Gaddis.``# Chapter Name: Expressions and Interactivity``# Chapter Number: 3``# Challenge Number: 25``# Challenge Name: Word Game``# ******************************************************************************``# Write a program that plays a word game with the user. The program should ask``# the user to enter the following:``# * His or her name``# * His or her age``# * The name of a city``# * The name of a college``# * A profession``# * A type of animal``# * A pet's name``# After the user has entered these items, the program should display the``# following story, inserting the user's input into the appropriate locations:``#``# There once was a person named NAME who lived in CITY. At the age of AGE, NAME``# went to college at COLLEGE. NAME graduated and went to work as a PROFESSION.``# Then, NAME adopted a(n) ANIMAL named PETNAME. They both lived happily ever after!``# ******************************************************************************`Code:`http://pythonmodules.googlecode.com/svn/trunk/Chapter3/src/C3Q25.py``

#### C3Q20: Angle Calculator

posted Jan 30, 2010, 6:27 AM by muh.adil@gmail.com

 `Program Description:`# ******************************************************************************``# Book Name: Starting Out with C++: Control Structures through Objects,``# Brief Version by Tony Gaddis.``# Chapter Name: Expressions and Interactivity``# Chapter Number: 3``# Challenge Number: 20``# Challenge Name: Angle Calculator``# ******************************************************************************``# Write a program that asks the user for an angle, entered in radians. The``# program should then display the sine, cosine, and tangent of the angle. (Use``# the sin, cos, and tan library functions to determine these values.) The output``# should be displayed in fixed-point notation, rounded to four decimal places of``# precision.``# ******************************************************************************`Code:`http://pythonmodules.googlecode.com/svn/trunk/Chapter3/src/C3Q20.py``

#### C4Q4: Areas of Rectangles

posted Jan 30, 2010, 6:19 AM by muh.adil@gmail.com   [ updated Jan 30, 2010, 6:20 AM ]

 `Program Description:`# ******************************************************************************``# Book Name: Starting Out with C++: Control Structures through Objects,``# Brief Version by Tony Gaddis.``# Chapter Name: Making Decisions``# Author: Adil Muhammad (itsaboutcode)``# Date: Jan 7 2010``# Chapter Number: 4``# Challenge Number: 4``# Challenge Name: Areas of Rectangles``# ******************************************************************************``# The area of a rectangle is the rectangle's length times its width. Write a``# program that asks for the length and width of two rectangles. The program``# should tell the user which rectangle has the greater area, or if the areas are``# the same.``# ******************************************************************************`Code:`http://pythonmodules.googlecode.com/svn/trunk/Python/Chapter4/src/C4Q4.py``

1-10 of 47