Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Comp 201 Lab Instructions for Spring 2008 - Lab 8 Problem 1, Lab Reports of Computer Science

Instructions for lab 8 problem 1 in comp 201, a computer programming course taken during spring 2008. Students are required to write a program that reads a text file and calculates the percentage of letters that are capitalized. An analysis, design, and code snippet for the lab.

Typology: Lab Reports

Pre 2010

Uploaded on 08/19/2009

koofers-user-2tk-1
koofers-user-2tk-1 🇺🇸

5

(1)

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Comp 201 Labs Spring 2008
Comp 201 Labs Spring 2008 Prof. M Werner
Lab Submission Rules
1. Lab grades are 0 .. 10, with 10 representing a correct lab turned in on time.
2. Labs lose 2 points for each week late.
3. Submit source files (.cpp and .h extensions), design chart and sample inputs and outputs.
4. Source files must have a heading clearly identifying the lab assignment, your name, the
submission date, and a brief description of the problem including inputs, processing and
outputs.
5. Labs may be submitted on paper, by e-mail. If by e-mail, submit each assignment as a
single zip file. Do not submit executables or other unreadable files.
6. Labs are to be done individually.
7. Lab Grades:
Points
Analysis Identify requirements (usually outputs),
inputs and processing
2
Design Include a correct chart as specified. Your
code must conform to the chart.
2
Correctness Include test runs verifying that the
program produces correct outputs
4
Programming style Is the code straight-forward, terse,
readable, properly indented?
2
Model Lab Submission (as a word doc)
/*********************************************************************
* Lab 8 Problem 1
* Melissa Mooney
* COMP128-01
* Nov 2, 2007
**********************************************************************
* Problem: Some languages such as German use more capitalization
* than other languages which share the same alphabet. To check
* this, a program is needed to read through a text file and
* calculate the percentage of letters that are capitalized.
***********************************************************************
* Analysis
*
12/1/2020 1 Prof. M Werner
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Comp 201 Lab Instructions for Spring 2008 - Lab 8 Problem 1 and more Lab Reports Computer Science in PDF only on Docsity!

Comp 201 Labs Spring 2008 Prof. M Werner

Lab Submission Rules

  1. Lab grades are 0 .. 10, with 10 representing a correct lab turned in on time.
  2. Labs lose 2 points for each week late.
  3. Submit source files (.cpp and .h extensions), design chart and sample inputs and outputs.
  4. Source files must have a heading clearly identifying the lab assignment, your name, the submission date, and a brief description of the problem including inputs, processing and outputs.
  5. Labs may be submitted on paper, by e-mail. If by e-mail, submit each assignment as a single zip file. Do not submit executables or other unreadable files.
  6. Labs are to be done individually.
  7. Lab Grades: Points Analysis Identify requirements (usually outputs), inputs and processing

Design Include a correct chart as specified. Your code must conform to the chart.

Correctness Include test runs verifying that the program produces correct outputs

Programming style Is the code straight-forward, terse, readable, properly indented?

Model Lab Submission (as a word doc)

  • Lab 8 Problem 1
  • Melissa Mooney
  • COMP128-
  • Nov 2, 2007

  • Problem: Some languages such as German use more capitalization
  • than other languages which share the same alphabet. To check
  • this, a program is needed to read through a text file and
  • calculate the percentage of letters that are capitalized.

  • Analysis

  • Inputs: A pre-existing text file

  • The name of the file (including the path)

  • Output: The percentage of letters that are capitalized

  • Error message if the named file cannot be opened


  • Design
  • Get file name from user
  • Open the file. If this fails give error message and die
  • Zero CapsCount, LowersCount
  • Scan the file char-by-char
  • if capital capsCount++
  • if lower lowersCount++
  • Divide CapsCount by LowersCount
  • Output result as a percent
  • See attached structure chart for functional decomposition **********************************************************************/ main isLower isCap processFile In : ifstream c : char c : char Gets file name Opens file Prints answer Scans chars from file Increments counts Returns ratio Returns true if c is a cap Returns true if c is lower case Structure Chart for Lab 8 Problem 1 #include #include using namespace std; double processFile(ifstream& in); bool isCap(char c); bool isLower(char c); int main(){ char filename[128]; ifstream in; cout << "Enter filename: "; cin >> filename;

Came whiffling through the tulgey wood, And burbled as it came! One, two! One, two! And through and through The vorpal blade went snicker-snack! He left it dead, and with its head He went galumphing back. "And hast thou slain the Jabberwock? Come to my arms, my beamish boy! O frabjous day! Callooh! Callay!" He chortled in his joy. 'Twas brillig, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe.

Lab 1 due Jan 21– Review of functions, loops, decisions

  1. Write a program to read through a file of numbers and calculate how many are positive and how many negative. Include a structure chart as in the model lab.
  2. Write a program to reverse capitalize all the letters in a text file, ie. capital letters are made lower case and lower case letters made capitals. Use 2 files: an input file for the original text, and an output file for the reverse-capitalized text. Include a structure chart as in the model lab.

Lab 2 due Jan 28 – Arrays and Sorting

  1. Computing a standard deviation. Refer to p. 437 Programming Project 4. Notice that computing a standard deviation requires 2 passes through the array, the first pass computes the average, and the second pass the sum of the squared deviations. Include a structure chart.
  2. Write a program that reads names and gpa’s from a text file. The file looks like: James 3. Margaret 3. Charles 1. Jennifer 4. Your program sorts the students ascending by gpa, and prints the sorted list including names. To keep the names with the numbers use parallel arrays, one for the names, the other for the numbers. Sort the numbers. Whenever you swap 2 numbers also swap their matching names in the names array. Include a structure chart as in the model lab.

Lab 3 due Feb 4 2-D arrays

  1. Program the “Game of Life”. See p. 442 Programming Project 13. Include a structure chart.

Lab 4 due Feb 11 Strings

  1. Write a program that reads in a text file and converts it to pig Latin. i.e. if the first letter is a consonant, move it to the end and add “ay” to the end, if it is a vowel add “way” to the end. Here’s an example: “end the war” becomes “endway hetay arway”. Include a structure chart.
  2. A file contains a list of names in the form: Jones, Frederick M Brennan, Claire Your program should alphabetize the list. Use the C++ string class. Also, extract names from the input stream with getline().

Lab 5 due Feb 18 Vectors

  1. Redo Lab 2 Problem 2, only this time use vectors to hold the names and gpa’s instead of arrays.. So you will work with 2 vectors, one holding the gpa’s (type double) and the other holding the names (type string).
  2. Write a program that reads in an entire text file, word-by-word, storing the words in a vector of string. Then sort the vector alphabetically and print it out. Test on the Gettysburg address.

Lab 6 Model Problem – Do not submit

  1. Write a class definition for a Fraction class. Its member fields are num and den, both of type int. The constructor builds the default fraction 1/1. It has the following operations: Fraction plus(const Fraction & second); //Returns a new fraction which is the sum of this fraction and the second fraction Fraction minus(const Fraction & second); //Returns a new fraction which equals this fraction minus second fraction Fraction times(const Fraction & second); // Returns a new fraction which equals this fraction times second fraction Fraction divides(const Fraction & second); // Returns a new fraction which equals this fraction divided by the second fraction void reduce(); // Reduces this fraction to lowest terms double todecimal(); //returns the decimal value of this fraction void scan(istream&); //scans a fraction written with a slash as in ¾ void print(ostream&); //prints a fraction using a slash Fraction(); //constructs a default fraction with denominator 1, numerator 0 Fraction(int n, int d); //constructs a fraction given value for num and den
  2. Write a menu-driven driver program designed to allow thorough testing of your Fraction class.

0.1 % of each other. i.e. 0.999*real1 < real2 < 1. real1. != Opposite of ==

  • Returns sum
  • Returns difference
  • Returns product / Returns quotient (a+bi)/(c+di) = (ac+bd)/(c^2 +d^2 ) + (bc-ad)i/(c^2 +d^2 ) ostream::operator<< Inserts a Complex number in the form a+bi into a stream ostream::operator>> Extracts a Complex number in the form a+bi from a stream

Lab 8 due Mar 17 A class using a dynamic array

p. 673 Programming Project #3 on creating a class that acts like a vector.

Lab 9 due Mar 24 Pointers and Linked Lists

  1. Write a linked list class named List for storing ints. The linked list is made up of nodes, which are structs with a next field and a data field. The List class should support insertion and removal at the head and insertion at the tail. One way to do this is efficiently is to have the list maintain pointers to both the head and tail. It should also support a print operation to print all the numbers in the order stored.
  2. P. 759 #2. In this problem you write a stand-alone merge function, which takes as arguments two ordered lists of int and merges them (in order) into a single list. To test your merge function, use the List class you built in Part 1 to construct two lists, each in ascending order. Then merge them into a new list and print out the results.

Lab 10 due Mar 31 Recursion

  1. Write and test recursive versions of strlen and strcpy.
  2. p. 803 Programming project 7 - A recursive sorting function

Lab 11 due Apr 7 Inheritance and Polymorphism

  1. P. 854 #7 –You will develop skeleton classes for graphics figures using inheritance and virtual functions.
  2. (Extra Credit) Modify your classes in Part 1 so that they actually draw things. You can do it crudely in a console application (See P. 855 #8), or more elegantly in a Windows application (See Lab 13).

Lab 12 due Apr 14 Exception Handling

  1. Page 887 Programming Project 1. A time manipulation program that throws an exception when an incorrect time value such as 25:05 is entered.
  1. (Extra Credit) Page 889 Programming Project 5. A stack that throws an exception on overflow or underflow.

Lab 13 due Apr 25 Building a Windows Program

The goal is to use Microsoft Foundation Classes (MFC) to build a simple windows program. The program allows the user to draw triangles in a window by dragging them out with the mouse. Follow this tutorial.

  1. Create a new MFC application named Box using the MFC Application template.
  2. When the MFC Application Wizard comes up press the Next button, change to “Single document”, then press Finish, i.e. accept all other defaults. This generates a lot of files.
  3. Build your program and test it by pressing the right arrow (debug). It puts up a window on the screen and opens a document inside it. There are menus and a toolbar and some limited functionality, i.e. you can resize the window, minimize it, close it, etc.
  4. Switch to Class View. Right-click on CBoxView and press (left-click) properties. This opens up the Properties window.
  1. Add a menu item allowing the user to choose between drawing a rectangle, an ellipse or a line by setting a mode variable.

Lab 14 due Apr 21 (optional) Enhancing the Windows Program

Implement some of the enhancements suggested at the end of the tutorials in Lab 12.

Lab Credits – Everyone should do at least 10 labs. Any additional

labs will count for extra credit.