Anne
Dawson: CSCI101A_FA_SP04.htm Wednesday
17th March 2004, 8:39 PT, AHD
This document is subject to change without notice.
Please
report any errors or omissions in this document to:
adawson@coquitlamcollege.com
Special instructions: For
this assignment you may work in teams of 2, or alone.
This assignment is due at the start of the last class of the
semester (Week 13 Class 2).
Final
Assignment Specification
------------------------------
The aim
of this assignment is to produce a C++ program (sim.cpp) that compares two C++
source code files and reports on their similarity. For example, if the two
source code files are identical, the program reports a similarity factor of
1.0. The similarity factor is determined (see examples below) from the total
number of characters in the file (including spaces and newline characters), the
number of C++ keywords in the file (not counting those within a comment), and
the number of C++ statements in the file. The number of C++ statements in the file
is determined by counting the number of semicolons in the file (except the two
semicolons in brackets after the keyword for of the for loop statement).
Assume that all comments are single line comments, i.e. those which start with
the characters // and end at the end of the line. A list of C++ keywords can be found in one of the appendices at
the back of the textbook. The filenames
of the files to be compared must be entered from the keyboard. The program
outputs a single number (the similarity factor) to the screen.
This document is subject to change without notice.
Example
1
---------
//345678901234567890123456789012345678901234567890123456789012345678901234567890
//
07-12.cpp Illustrates the for statement
#include
<iostream.h>
void main(void)
{
int product = 0;
for (int i = 1; i <= 5; i++) //Note that the variable i is a local
variable
product = product * i;
cout << "The final result is
"
<< product << endl;
}
Characters:
353
Keywords:
5
Statements:
3
//345678901234567890123456789012345678901234567890123456789012345678901234567890
//
07-14.cpp Sums a list of 5 negative numbers.
#include
<iostream.h>
#include
<conio.h>
int
main( )
{
int number, sum = 0, count = 0;
cout << "Enter 5 negative
numbers:\n";
while (count < 5)
{
cin >> number;
if (number >= 0)
{
cout << "ERROR:
positive number"
<< " or zero was
entered as the\n"
<< count <<
"th number! Input ends "
<< "with the
" << count << "th number.\n"
<< count <<
"th number was not added in.\n";
break;
}
sum = sum + number;
count++;
}
cout << sum << " is the
sum of the "
<< (count) << " negative numbers.\n";
getch();
return 0;
}
Characters:
791
Keywords:
6
Statements:
10
Similarity
factor: (353/791) *
(5/6) * (3/10)
= 0.446 * 0.833 * 0.3 = 0.111
If
similarity factor > 1 then similarity factor = 1/similarity factor
Example
2
---------
//345678901234567890123456789012345678901234567890123456789012345678901234567890
//
07-14.cpp Illustrates the for statement
#include
<iostream.h>
void
main(void)
{
int product = 0;
for (int i = 1; i <= 5; i++) //Note that the variable i is a local
variable
product = product * i;
cout << "The final result is
"
<< product << endl;
}
Characters:
353
Keywords:
5
Statements:
3
//345678901234567890123456789012345678901234567890123456789012345678901234567890
// 07-14.cpp
Illustrates the for statement
#include
<iostream.h>
void
main(void)
{
int product = 0;
for (int i = 1; i <= 5; i++) //Note that the variable i is a local
variable
product = product * i;
cout << "The final result is
"
<< product << endl;
}
Characters:
353
Keywords:
5
Statements:
3
Similarity
factor: (353/353) *
(5/5) * (3/3)
= 1.0 * 1.0 * 1.0 = 1.0
If
similarity factor > 1 then similarity factor = 1/similarity factor
This document is subject to change without notice.
Submission
instructions
-----------------------
At the
start of class (Week 13 Class 2) you should save just your source code file to
your folder in CSCI101A\Week13\FA.
If you
are working in a team, both team members save the same file to their own
folder.
Marking
Scheme
--------------
The
following marking scheme applies:
Course
Code: CSCI101A
Semester: SP04
Assignment
Code: Final Assignment
Lab
Specification: Similarity between
files (sim.cpp)
Instructor
Name: Dr Anne Dawson
Student
1 Name:
Student
1 Number:
Student
2 Name:
Student
2 Number:
DESIGN
1. The program has appropriate modularity
i.e.
functions are used where it makes sense to
use them. /10
2. Appropriate data types and control
structures
are used. /10
3. The program is robust
(handles exceptional circumstances). /10
4. The program is efficient
(does not contain unnecessary
statements) /10
MAINTAINABILITY
5. The program is commented appropriately -
including
date, filename and pre- and post-condition
comments. /10
6. The program has meaningful identifiers. /10
7. The program is indented (spaced out)
correctly, to
aid the understanding of the code. /10
8. The code is easy to follow. /10
CORRECTNESS:
9. The program runs as intended (is
accurate). /10
10.
Comprehensive test data and results are supplied. /10
%
Complete:
Bonus:
Total: /100
Date: