-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangyuan0102
committed
Mar 14, 2024
1 parent
bb8797d
commit f214ff5
Showing
78 changed files
with
4,925 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Ok, now you've been walked through editing, saving, | ||
and submitting an assignment. For this assignment, we're just going | ||
to have you practice that on your own before | ||
we move on to things involving writing code. | ||
|
||
- Create a file called "fruit.txt" | ||
- Write one line, containing the text | ||
apple | ||
into that file | ||
- Save the file and submit the assignment for grading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
apple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Grading at Fri 09 Feb 2024 06:17:37 AM UTC | ||
Your file matched the expected output | ||
|
||
Overall Grade: PASSED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Open the code1.c file you have in this directory. | ||
You will see two functions: max and main. | ||
|
||
In max, the algorithm is written as comments, but there is no code. | ||
You should translate this algorithm to code. | ||
|
||
In main, there are three print statements which call max and print | ||
its result. These would let you check if max is working right. | ||
|
||
There is also a comment asking you to write one more print statement | ||
with a call to max. In that comment, it asks you to take the max | ||
of two numbers (written as hex), and print them out. | ||
Add a line of code to do this. | ||
|
||
When you have done this, run | ||
|
||
./test.sh | ||
|
||
This script will try to compile your code (which you will learn about in | ||
the next chapter), as well as run it. If your code does not have legal | ||
syntax, it will do its best to describe what is wrong. If there | ||
is a problem, look at the code and try to see where you did not follow | ||
the syntax rules from chapter 2. The line number and message it gives | ||
may help you find the problem. If you cannot find the problem after a minute | ||
or two, ask for help. | ||
|
||
If your code has legal syntax, test.sh will also run it, and show | ||
you the output it produced, as well as the output we expected. | ||
|
||
If they are the same, you should commit, push, and grade. | ||
|
||
If they are not, you should see if you can fix the problem (and ask for help | ||
if you cannot). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
int max (int num1, int num2) { | ||
if(num1>num2){//check if num1 is greater than num2 | ||
return num1; | ||
} | ||
|
||
else{ | ||
return num2; | ||
}//f so, your answer is num1 | ||
//otherwise, your answer is num2 | ||
} | ||
|
||
int main(void) { | ||
printf("max(42, -69) is %d\n", max(42, -69)); | ||
printf("max(33, 0) is %d\n", max(33, 0)); | ||
printf("max(0x123456, 123456) is %d\n", max(0x123456, 123456)); | ||
printf("max(0x451215AF,0x913591AF) is %d\n",max(0x451215AF,0x913591AF)); | ||
//e the max of 0x451215AF and 0x913591AF and print it out as a decimal number | ||
|
||
return 0; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
Grading at Fri 09 Feb 2024 06:59:08 AM UTC | ||
Checking code1.c for legal syntax | ||
Checking for int max (int num1, int num2) | ||
Found on line 3, column 1 | ||
Checking for int main(void) | ||
Found on line 14, column 1 | ||
Trying to run the code.. | ||
Your file matched the expected output | ||
Removing your main() and replacing it with our own to run more tests... | ||
Testing max(-999, -2147483648) ... Correct | ||
Testing max(-999, 123) ... Correct | ||
Testing max(-999, 567) ... Correct | ||
Testing max(-999, 891) ... Correct | ||
Testing max(-999, 0) ... Correct | ||
Testing max(-999, 1) ... Correct | ||
Testing max(-999, -999) ... Correct | ||
Testing max(-999, 123123123) ... Correct | ||
Testing max(-87, -2147483648) ... Correct | ||
Testing max(-87, 123) ... Correct | ||
Testing max(-87, 567) ... Correct | ||
Testing max(-87, 891) ... Correct | ||
Testing max(-87, 0) ... Correct | ||
Testing max(-87, 1) ... Correct | ||
Testing max(-87, -999) ... Correct | ||
Testing max(-87, 123123123) ... Correct | ||
Testing max(0, -2147483648) ... Correct | ||
Testing max(0, 123) ... Correct | ||
Testing max(0, 567) ... Correct | ||
Testing max(0, 891) ... Correct | ||
Testing max(0, 0) ... Correct | ||
Testing max(0, 1) ... Correct | ||
Testing max(0, -999) ... Correct | ||
Testing max(0, 123123123) ... Correct | ||
Testing max(1, -2147483648) ... Correct | ||
Testing max(1, 123) ... Correct | ||
Testing max(1, 567) ... Correct | ||
Testing max(1, 891) ... Correct | ||
Testing max(1, 0) ... Correct | ||
Testing max(1, 1) ... Correct | ||
Testing max(1, -999) ... Correct | ||
Testing max(1, 123123123) ... Correct | ||
Testing max(240, -2147483648) ... Correct | ||
Testing max(240, 123) ... Correct | ||
Testing max(240, 567) ... Correct | ||
Testing max(240, 891) ... Correct | ||
Testing max(240, 0) ... Correct | ||
Testing max(240, 1) ... Correct | ||
Testing max(240, -999) ... Correct | ||
Testing max(240, 123123123) ... Correct | ||
Testing max(345, -2147483648) ... Correct | ||
Testing max(345, 123) ... Correct | ||
Testing max(345, 567) ... Correct | ||
Testing max(345, 891) ... Correct | ||
Testing max(345, 0) ... Correct | ||
Testing max(345, 1) ... Correct | ||
Testing max(345, -999) ... Correct | ||
Testing max(345, 123123123) ... Correct | ||
Testing max(999999, -2147483648) ... Correct | ||
Testing max(999999, 123) ... Correct | ||
Testing max(999999, 567) ... Correct | ||
Testing max(999999, 891) ... Correct | ||
Testing max(999999, 0) ... Correct | ||
Testing max(999999, 1) ... Correct | ||
Testing max(999999, -999) ... Correct | ||
Testing max(999999, 123123123) ... Correct | ||
Testing max(2147483647, -2147483648) ... Correct | ||
Testing max(2147483647, 123) ... Correct | ||
Testing max(2147483647, 567) ... Correct | ||
Testing max(2147483647, 891) ... Correct | ||
Testing max(2147483647, 0) ... Correct | ||
Testing max(2147483647, 1) ... Correct | ||
Testing max(2147483647, -999) ... Correct | ||
Testing max(2147483647, 123123123) ... Correct | ||
|
||
Overall Grade: A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
cat > temp.c <<EOF | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
EOF | ||
cat code1.c >> temp.c | ||
gcc -Wall -Werror -pedantic -std=gnu99 temp.c -o code1 2>errors.txt | ||
if [ "$?" = "0" ] | ||
then | ||
echo "Your code appears to have legal syntax!" | ||
echo "Here is what I get when I run it..." | ||
echo "-----------------" | ||
./code1 | ||
echo "-----------------" | ||
echo "Here is what I would expect the answers to be:" | ||
echo "----------------" | ||
cat <<EOF | ||
max(42,-69) is 42 | ||
max(33,0) is 33 | ||
max(0x123456,123456) is 1193046 | ||
max(0x451215AF, 0x913591AF) is 1158813103 | ||
EOF | ||
echo "---------------" | ||
else | ||
echo "Oh no, the syntax of your code is not correct!" | ||
mesg=`grep error errors.txt | head -1` | ||
ln=`echo "$mesg" | cut -f2 -d":"` | ||
let ln=${ln}-2 | ||
echo "I discovered the problem on line $ln " | ||
echo "(though the problem may be earlier and I just got confused)" | ||
echo "Here is my best attempt to describe what is wrong:" | ||
echo "$mesg" | cut -f5 -d":" | ||
fi | ||
rm -f temp.c errors.txt code1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Open the code2.c file you have in this directory. | ||
You will see two functions: printTriangle and main. | ||
|
||
As with the previous problem, the printTriangle function | ||
has an algorithm written as comments, but there is no code. | ||
You should translate this algorithm to code. | ||
|
||
In main, there are three print statements which print out a triangle | ||
with height 4, and the total number of stars in that triangle (returned | ||
by the printTriangle function). | ||
|
||
There is also a comment asking you to write a few more statements | ||
to do the same thing for a triangle of height 7. | ||
Add the code to do this. | ||
|
||
When you have done this, run | ||
|
||
./test.sh | ||
|
||
As before, this script will try to compile your code (which you will learn about | ||
ina n upcoming lesson), as well as run it. If your code does not have legal | ||
syntax, it will do its best to describe what is wrong. If there | ||
is a problem, look at the code and try to see where you did not follow | ||
the syntax rules from Course 1 The line number and message it gives | ||
may help you find the problem. If you cannot find the problem after a minute | ||
or two, ask for help. | ||
|
||
If your code has legal syntax, test.sh will also run it, and show | ||
you the output it produced, as well as the output we expected. | ||
|
||
If they are the same, you should commit, push, and grade. | ||
|
||
If they are not, you should see if you can fix the problem (and ask for help | ||
if you cannot). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
int printTriangle(int size) { | ||
//start with starCount being 0 | ||
int starCount=0; | ||
int i; | ||
int j; | ||
//count from 0 (inclusive) to size (exclusive), for each number i that you count | ||
for(i=0;i<size;i++){ | ||
|
||
//count from 0 (inclusive) to i (inclusive), for each number j that you count | ||
for(j=0;j<=i;j++){ | ||
printf("*"); | ||
starCount++; | ||
} | ||
//print a "*;" | ||
printf("\n"); | ||
} | ||
return starCount; | ||
//increment starCount; | ||
|
||
//when you finish counting on j, | ||
|
||
//print a newline ("\n") | ||
|
||
//when you finish counting on i, | ||
|
||
//your answer is starCoun | ||
} | ||
|
||
|
||
int main(void) { | ||
int numStars; | ||
printf("Here is a triangle with height 4\n"); | ||
numStars = printTriangle(4); | ||
printf("That triangle had %d total stars\n", numStars); | ||
//now print "Here is a triangle with height 7\n" | ||
printf("Here is a triangle with height 7\n"); | ||
//then call printTriangle, passing in 7, and assign the result to numStars | ||
numStars = printTriangle(7); | ||
//finally, print "That triangle had %d total stars\n", such that the % | ||
printf("That triangle had %d total stars\n",numStars); | ||
//prints the value of numStars | ||
|
||
|
||
return 0; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Grading at Fri 09 Feb 2024 10:14:14 AM UTC | ||
Checking code2.c for legal syntax | ||
Checking for int printTriangle (int size) | ||
Found on line 4, column 1 | ||
Checking for int main(void) | ||
Found on line 33, column 1 | ||
Trying to run the code.. | ||
Your file matched the expected output | ||
Removing your main() and replacing it with our own to run more tests... | ||
Testing printTriangle(0) ... Correct | ||
Testing printTriangle(1) ... Correct | ||
Testing printTriangle(2) ... Correct | ||
Testing printTriangle(3) ... Correct | ||
Testing printTriangle(4) ... Correct | ||
Testing printTriangle(7) ... Correct | ||
Testing printTriangle(9) ... Correct | ||
Testing printTriangle(12) ... Correct | ||
Testing printTriangle(98) ... Correct | ||
Testing printTriangle(209) ... Correct | ||
Testing printTriangle(501) ... Correct | ||
Testing printTriangle(2374) ... Correct | ||
|
||
Overall Grade: A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
cat > temp.c <<EOF | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
EOF | ||
cat code2.c >> temp.c | ||
gcc -Wall -Werror -pedantic -std=gnu99 temp.c -o code2 2>errors.txt | ||
if [ "$?" = "0" ] | ||
then | ||
echo "Your code appears to have legal syntax!" | ||
echo "Here is what I get when I run it..." | ||
echo "-----------------" | ||
./code2 | ||
echo "-----------------" | ||
echo "Here is what I would expect the answers to be:" | ||
echo "----------------" | ||
cat <<EOF | ||
Here is a triangle with height 4 | ||
* | ||
** | ||
*** | ||
**** | ||
That triangle had 10 total stars | ||
Here is a triangle with height 7 | ||
* | ||
** | ||
*** | ||
**** | ||
***** | ||
****** | ||
******* | ||
That triangle had 28 total stars | ||
EOF | ||
echo "---------------" | ||
else | ||
echo "Oh no, the syntax of your code is not correct!" | ||
mesg=`grep error errors.txt | head -1` | ||
ln=`echo "$mesg" | cut -f2 -d":"` | ||
let ln=${ln}-2 | ||
echo "I discovered the problem on line $ln " | ||
echo "(though the problem may be earlier and I just got confused)" | ||
echo "Here is my best attempt to describe what is wrong:" | ||
echo "$mesg" | cut -f5 -d":" | ||
fi | ||
rm -f errors.txt temp.c code2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
For this assignment, you will be practicing writing, compiling, and | ||
running code. You should write a C file, called hello.c, with a main | ||
function that uses the printf function to print the message | ||
|
||
Hello World | ||
|
||
[be sure to include a newline!] | ||
|
||
Your program should return EXIT_SUCCESS to indicate that it was successful | ||
(the return value of main indicates success [0] or failure [anything else]). | ||
|
||
Don't forget to include stdio.h (for printf) and stdlib.h (for | ||
EXIT_SUCCESS). | ||
|
||
When you are done, compile your code and run it. | ||
The submit it for grading. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Grading at Fri 09 Feb 2024 10:35:47 AM UTC | ||
Compiling your code | ||
Checking if your program prints "Hello World" | ||
Your file matched the expected output | ||
|
||
Overall Grade: PASSED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
int main(void){ | ||
printf("Hello World\n"); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
squares |
Oops, something went wrong.