-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw02_skynet.html
185 lines (183 loc) · 8.94 KB
/
hw02_skynet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<html>
<head>
<title>ESE 116 Spring 2008, Homework 2: Skynet</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="file:///Macintosh HD/Users/jeaniacgriffin/Documents/Sites/cis110/content/style.css" type="text/css">
<style type="text/css">
<!--
.style2 {font-size: 60px}
.style3 {font-size: 20px}
.style4 {color: #FF0000}
.style5 {
color: #FF0000;
font-weight: bold;
}
-->
</style>
</head>
<body bgcolor="#FFFFFF">
<table width="750px" border="1">
<tr>
<td><span class="style2">SkyNet:</span></td>
<td width="81%"><div align="left"><span class="style3">The SkyNet Project, funded by DARPA and Microsoft<br>
</span></div></td>
</tr>
</table>
<h3> Files:</h3>
<ul>
<li>Needed to <em>code</em> your program:
<ul>
<li><a href="./skynet.c">skynet.c</a> (to be completed / submitted)</li>
<li><a href="./skynet_main.c">skynet_main.c</a> (needed for skynet.c to compile)</li>
<li><a href="./skynet.h">skynet.h</a> (needed for skynet.c to compile)<br>
</li>
</ul>
</li>
<li>Suggested for <em>testing</em> your program:
<ul>
<li><a href="./sample_output.txt">sample_output.txt</a> (sample output of a working program)</li>
</ul>
</li>
</ul>
<h3>Purposes of this assignment:</h3>
To practice:
<ul>
<li>Working with C <a href="http://computer.howstuffworks.com/c12.htm">functions</a>, function calls, and return values </li>
<li>Working with C <a href="http://www.space.unibe.ch/comp_doc/c_manual/C/CONCEPT/data_types.html">floats and doubles </a></li>
<li>Using the <a href="http://linux.die.net/man/3/printf">printf</a> function </li>
<li>Using <a href="http://www.geocities.com/learnprogramming123/Clesson8Beginner.htm">for and while</a> loops</li>
<li>Using C Implicit & Explicit <a href="http://www.cplusplus.com/doc/tutorial/typecasting.html">type casting</a> </li>
</ul>
<h3>Important Notes:</h3>
<ul>
<li><span class="style4">START THIS HOMEWORK EARLY</span> ... it is significantly longer than the last one. <br>
</li>
<li>Homework assignments should be <strong>done alone</strong>.
<ul>
<li>Help is available via the <a href="https://alliance.seas.upenn.edu/~cis1xx/cgi-bin/cis1xxBB/index.php">bulletin board</a> and office hours.</li>
</ul>
</li>
<li>Please be respectful of the TAs' time and refrain from emailing them individually.
<ul>
<li> The TA's take turns answering questions on the bulletin board. </li>
<li>Please ask questions on the bulletin board or bring them to office hours.</li>
</ul>
</li>
<li>At the top of the <a href="https://www.seas.upenn.edu/~ese116/content/content.shtml">Content page</a>
<ul>
<li>Read the <a href="https://www.seas.upenn.edu/~cis1xx/resources/homeworkPolicy.shtml">Homework Submission and Policy Information</a> </li>
<li>See the link to use for submitting homework. </li>
</ul>
<li>We highly recommend that you <strong>test your program in the lab or on the Eniac server before turning it in</strong>.
<ul>
<li>There can sometimes be differences between your home setup and the lab / Eniac cluster that can cause errors in your code while grading. </li>
</ul>
<li>Do <strong>not</strong> modify skynet.h or skynet_main.c for your program
<ul>
<li>We will be using the given versions when we grade your code.</li>
</ul>
</ul>
<h3>Editing Hints:</h3>
<ul>
<li>Tab your code correctly. Doing this makes errors more obvious and easier to debug.
<ul>
<li>By hitting 'tab' on any line of code, EMACS does this automatically</li>
<li>TAs & Mentors <3 properly tabbed code </li>
</ul>
</li>
</ul>
<h3>Overview:</h3>
<p>As promised in the <a href="http://www.seas.upenn.edu/~cis1xx/projects/CandC++/GettingStarted/HalCalculator_v2/hw01_hal.html">previous lab</a>, you will now be building <a href="http://en.wikipedia.org/wiki/Skynet_(fictional)">SkyNet</a>. Commissioned by <a href="http://www.darpa.mil/">DARPA</a> and overseen by <a href="http://mshiltonj.com/software_wars/current/">Microsoft</a>, SkyNet is a comprehensive computer-based defense system. It is designed to remove the possibility of human error and slowness of reaction time to guarantee fast, efficient response to enemy attack.</p>
<p><span class="style4"><strong>Detailed function descriptions are in the function headers in skynet.c</strong></span><span class="style5">, pl</span><span class="style4"><strong>ease fill out the functions according to the specifications.</strong></span>
</p>
<p>
The file <strong>skynet.c</strong> contains 5 functions that you will have to complete. <br>
Detailed specifications are in comments at the top of each function:</p>
<ul>
<li>The <strong>count_down() </strong>function
<ul>
<li>The purpose of this function is to begin the countdown of the SkyNet initiation protocol</li>
</ul>
</li>
<li>The <strong>get_human_max_age()</strong> function.
<ul>
<li>The purpose of this function is to calculate the maximum age of a human, as inputted by the user</li>
</ul>
</li>
<li>The <strong>get_human_average_age()</strong> function.
<ul>
<li>The purpose of this function is to calculate the average age of the human ages inputted by the user</li>
</ul>
</li>
<li>The <strong>calculate_resistance()</strong> function.
<ul>
<li>The purpose of this function is to calculate the expected human resistance, and the response the humans will send. </li>
</ul>
</li>
<li>The <strong>query_user()</strong> function.
<ul>
<li>The purpose of this function is to query the user for a menu option</li>
<li>You are required to use a <a href="http://en.wikipedia.org/wiki/Switch_statement">switch statement</a> to complete this function. </li>
</ul>
</li>
</ul>
<p>The file <strong>skynet_main.c</strong> contains four functions you must utilize to write the skynet.c functions. <strong>Do not </strong>modify these functions, you must use them in their current form:</p>
<ul>
<li><strong>float get_float_from_terminal()</strong><ul>
<li>Retrieves one float value from the terminal, and returns this float</li>
<li class="style4">This function should only be used in the get_human_average_age() function</li>
</ul>
</li>
<li><strong>int get_integer_from_terminal()</strong><ul><li>It retrieves one integer value from the terminal, and returns this integer</li>
</ul>
</li>
<li><strong>char get_character_from_terminal()</strong><ul><li>It retrieves one character value from the terminal, and returns this character</li>
</ul>
</li>
<li><strong>void print_countdown_int(int print_int)</strong>
<ul>
<li>Prints a single countdown integer in the format "Countdown: %d\n".</li>
<li class="style4">Be sure to use this function in your count_down() function</li>
</ul>
</li>
</ul>
<p>The following definitions are in skynet.h:<br>
</p>
<ul>
<li><strong>For the calculate_resistance() function:
</strong>
<ul>
<li>CARE_BEARS is defined as 0</li>
<li>TONY_STARK is defined as 1</li>
<li>BATMAN is defined as 2</li>
<li>CHUCK_NORRIS is defined as 3</li>
</ul>
</li>
<li><strong>For the query_user() function:</strong>
<ul>
<li>MENU_COUNTDOWN is defined as 0</li>
<li>MENU_MAX_AGE is defined as 1</li>
<li>MENU_AVG_AGE is defined as 2</li>
<li>MENU_RESISTANCE is defined as 3</li>
<li>MENU_HELP is defined as 4</li>
<li>MENU_EXIT is defined as 5</li>
<li>MENU_ERROR is defined as 6</li>
</ul>
</li>
</ul>
<p>Remember to use the above #defines when told to do so, DO NOT use the literal integer (0, 1, etc)</p>
<p>To compile your code to a binary executable called 'skynet', type in the following at the command line, assuming your skynet.c, skynet_main.c and skynet.h files are in your current working directory:</p>
<pre> gcc -Wall skynet_main.c skynet.c -o skynet</pre>
<p>The '-Wall' flag will print out all warnings that the compilation generates. It is highly recommended that you eliminate warnings in your coding, as warnings can often lead to undefined behavior in your programs.</p>
<p>After executing the code above, the following line can be used to execute your program:</p>
<pre> ./skynet</pre>
<p>To assist you in testing, we have also included some sample output from a working version of the program to demonstrate how your program should operate once completed.</p>
<p>Remember, to kill the foreground process in the terminal, hit (CTRL+C). This might come in handy if you need to kill a program you are testing.</p>
<h3>Printf Example:</h3>
<p>The following example usage of the printf statement: </p>
<pre> printf("Color %s, number1 %d, number2 %05d, hex %x, float %.2f, unsigned value %u.\n","red", 123456, 89, 255, 3.141, 250);</pre>
<p>will print following line (including new-line character, \n):</p>
<pre> Color red, number1 123456, number2 00089, hex ff, float 3.14, unsigned value 250.</pre>
<hr>
</body>
</html>