Syllabus

Home

Class Resources

 

Class Resources for CS-102:
Introduction to C Programming

General

Semester Calendar
Getting Started - Course Basics

Additional Resources

Download Microsoft Visual Studio Ultimate FREE from Microsoft
Get Visual Studio from UAH for FREE - Unlimited Use
How to use Visual Studio 2012 in this Course (MS Word Doc)
Example of Homework (MS Word)
C Program Template

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

int main(void)

{

 

printf("\n\n\n");
system("pause");

}


Chapter 2 Sections 2.1 & 2.2 Screen Output

In Class Problem 1: welcome.c (C Source File) Download this file (Save Target As) and add it to a New Project
In Class Problem 2: Write a C Program that prints the following to the screen:
Course: CS 102
Date: August 27, 2012
Author: Sam Jones
Problem: In Class Problem 2
In Class Problem 3: Write a C program called special.c that prints the special characters
backslash, double quote, single quote, and percent sign.

The output should look like this.
Screenshot showing output from special.c prpgram

In Class Problem 4: Write a program that produces the design shown below.
Output of design.c program
Want a challenge? Try making this elephant design.
Screeen capture showing elephant design with letters
In Class Problem 5: debug_one.c Download the file. Correct the Errors.

Output should look like this.
Output of In Class exercise one

Chapter 2 Sections 2.3, 2.4 & 2.5 Keyboard Input and Calculations

In Class Problem 6:
Part A: Calculate area of a rectangle given values for length and width.
Part B: Modify program so that it imports values for length and width from keyboard
.
In Class Problem 7:
Part A: Calculate driving time given distance and avg speed.
Part B: Modify program so that it imports values for average speed and distance from keyboard
.

Sample output from In Class problems 6 and 7
Screen capture of output from in class problems 6 and 7

In Class Problem 8: Temperature Conversion
Write a program that prompts the user to enter a temperature in degrees Celsius and then outputs the equivalent temperature in degees Fahrenheit. F = 9/5 C + 32.0

Sample output for in class problem 8
Screen output of temperature conversion program

In Class Problem 9: Body Mass Index
Write a program that prompts the user to enter their height in feet and inches and their weight in pounds and then computes their Body Mass Index (BMI) where: BMI = weight divided by the height in inches squared and the result multiplied by 703.

Sample output from in class problem 9
Screen output from BMI program

In Class Problem 10: Water Tank Volume
Write a program that prompts the user to enter the radius for a spherical water tank and then computes the volume of water that the tank can hold.
Volume in cubic feet = 4/3 times PI times the radius cubed.
One cubic foot of water contains 7.48 gallons.

Sample output from problem 10
Screen capture of output from volume of water tank problem

In Class Problem 11: Mileage
Write a program that prompts the user to enter three real numbers: Odometer reading at last fill up; current odometer reading; and gallons of gas purchased to fill the tank. Compute and print out the milage in miles per gallon since the last fill up.
Sample output from problem 11
Screen capture of output from gs mileage program

Chapter 2 Section 2.6 Conditionals

In Class Problem 12: Largest of Three Integers

Design and write a program that detects the largest of three integer numbers. The program should prompt the user to enter the numbers, determine the largest value and then output the three original numbers and then the largest value. Write the results to the console with printf.
Part 2: Add code to the above program that creates a text file and writes your name and the three numbers plus largest number to the file. Refer to the file output programs belwo for examples. Also refer to the program on page 55 of your textbook.
SOLUTIONS (File Output)

Writing output to a text file: To be added
SOLUTIONS

Solutions to the find largest of three integers problem: To be added
Short solution with two simple if statements: To be added

Chapter 3

In Class Problem 13: Convert C to F with While Loop
Write a program that prompts the user to enter a temperature in degrees Celsius and then outputs the equivalent temperature in degees Fahrenheit. After each value is converted and printed to the screen give the user the option to enter another value. The user will enter 1 to continue and 0 to terminate the program. F = 9/5 C + 32.0

Sample output from problem 13
Screen output of temperature conversion program

In Class Problem 14: Create C to F Temperature Table
Design and write a program that prompts the user to enter a starting temperature and an ending temperature in degrees Celsius. The program then creates and prints to the console a table of values for C and F at 5 degree increments.

Part2: Modify the program above to allow the user to input a value for the the increment between values of C in the table.

Sample putput from problem 14
Example output from temperature table program

 

In Class Problem 15: Determine Marimum, Minimum and Avergage Value
Design and write a program that allows the user to enter a sequence of positive real numbers then determines the maximum, minimum and average of the entered values. Use a while loop to repeatedly prompt the user to enter a value. Declare a variable (e.g. counter) to keep track of the number of entries. An input sentinel of -1 will cause the loop to terminate. Following the loop calculate the average of the input numbers then print the maximum, minimum and the average to the console.
Sample output from problem 15
Output from min max average program
In Class Problem 16: Day of week with validated input
Design and write a program that allows the user to enter an integer between 1 and 7 that represents the day of the week Sunday through Saturday. After reading the user input the program validates the input. If the value is not valid then the user is given an error message and asked to reenter the value. (Implement this with a While loop) If a valid number is input then the number is tested and the corresponding day is prnted to the console.

Sample output from problem 16
Output of day of week program

In Class Problem 17: Body Mass Index Table
Write a program that prompts the user to enter their height in feet and inches and then produces a table of BMI values where the weight ranges from 100 to 200 pounds in increments of 10. BMI = weight divided by the height in inches squared and the result multiplied by 703.
Part2: Modify the program to allow the user to specify the beginning weight, ending weight and the increment between rows of the table.
Part 3: Modify the program such that the table is written to a text file.
Sample output from part one of the program
Screen output from BMI Table program
In Class Problem 18: Guess the Number

Write a program that implements a number guessing game. The user will be prompted to enter a number between 1 and 100. Then the program will check the guess to see if it matches the number (which is hard coded into a variable in the program). If the guess is too low the player will be told that their guess is too low and they will be given a chance to enter a new guess. Similarly, if they enter a number that is too high they will be told that their guess is too high and they will be given a chance to enter another guess. When they guess the number print the message "Congratulations! You Win!" to the console.
Part 2: Modify the program to limit the number of guesses to 10. If the user is not able to guess the number in 10 trys print a message to the console that informs them that they have no more guesses and give them the secret number.

Sample execution of the Guess Number program.
Output of the guess the number problem

Chapter 4


Chapter 5


Chapter 6


Special Topics