Note the following demographic characteristics of the code you find: url for the
ID: 3685670 • Letter: N
Question
Note the following demographic characteristics of the code you find:
url for the site
stated purpose of the code
date created/modified if possible
part of larger system (yes or no if your sample is the complete program).
stated purpose of entire system (game, utility, operating system, device driver, web browser, etc. etc.)
Run your program once on a sample of C, and once on a sample of another "C-like" language. You can try any language you like, but the ones I think are most similar to C in syntax are Java and it's step-cousin, JavaScript. The scripting language Perl bears a strong resemblance as well. I think PHP will appear similar, as will C# and C++ (Duh). Languages such as Python and Lua will be much less similar, although for some very basic constructs, such as if and else, should still show non-zero counts.
After you write and test your program, you are asked to post the statistics you compute on a new thread in the Project 4 - Code Analysis Discussion Forum.
There are two parts to completing this assignment:
1. You submit the code you develop as an assignment to receive credit. An assignment submission link appears in the folder containing this project.
2. You post the statistics you calculate for at least two language samples, one in C and one in another language of your choice. You are welcome to run your program on more than two languages and share the results, of course.
Details
Select C/C++ code from 'Net. Try to find at least least 500 lines (1,000 would be better). Here's a starter Google search:
https://www.google.com/#q=c+source+code+
You can do better. Pick the source code to something of interest to you. Google Code, GitHub and SourceForge are all possible sources as well.
Do a similar search to locate a comparatively-sized code sample in a non-C language, too.
Count and compute:
number of total lines
number and percentage of blank lines
number and percentage of comments (start with // or /*)
number and percentages of ints, longs, floats, doubles, char
number and percentages of if's
number and percentage of else's
number and percentage of for's
number and percentage of switch
number and percentage of semicolons
number and percentage of structs
number and percentage of arrays (contains [ or ], divide count by 2)
number of blocks (contains { or }, divide count by 2)
for each language sample.
If you can think of some other easy pattern to match, feel free to throw that in, too.
Demographic information.
This is background information about the context for the code you analyzed. Stuff like the purpose of the program, when it was written, and where you found it.
Record:
URL
stated purpose of the code
date created/modified if possible
part of larger system
stated purpose of entire system
Approach
Here are some hints for how to approach this problem:
Check the links in the Module Resources folder here, and find other resources on the 'Net to explain how to do the following:
fopen ( ) and fclose ( ) a text file.
fgets ( ) each line into a char array. I think this will be easier than scanf ( ) here.
use C string functions to scan for each keyword –the function named strstr ( ) is your friend
Count each keyword you find, tracking that using an int variable for each keyword.
Remember that you need to scan each line for all keywords, since a line can have, say an if AND a comment.
Compute percentages – basically (number of X divided by total number of lines) * 100. You will need to use a double here to avoid losing everything to the right of the decimal.
Print all statistics on stdout (can redirect to a file for easy saving)
Testing
Have your program print each line that it matches, preceded by "blank:", "if:" and so on and then randomly check some to see if you are finding the right stuff, or being distracted by some irrelevant text. This will produce a lot of output, but if you save it in a file, you can open that file in your text editor, and search through it for each keyword, and see if what your program found matches what your editor locates.
Explanation / Answer
Agree with Michael Toon. Its possible
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.