Skip to content

Commit 1ea977a

Browse files
committed
Add sample submission folder
1 parent f43070f commit 1ea977a

File tree

17 files changed

+314
-7
lines changed

17 files changed

+314
-7
lines changed

grading/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

grading/p0/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
results

grading/p0/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Grading folder
2+
3+
To run the grading script for P0, run `../grade.sh` from this folder.
4+

grading/p0/project.include

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ FILES="main.c p0-intro.c"
77
REFFILES="p0-intro.h Makefile tests"
88

99
# paths
10-
REF="/path/to/reference"
11-
SUBMIT="/path/to/submissions"
12-
RESULTS="/path/to/results"
10+
REF="../../ref/p0-intro"
11+
SUBMIT="../submissions"
12+
RESULTS="./results"
1313

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* CS 261: Intro project driver
3+
*
4+
* Name:
5+
*/
6+
7+
#include "p0-intro.h"
8+
9+
int main (int argc, char **argv)
10+
{
11+
// BEGIN_SOLUTION
12+
13+
const size_t BUFFER_SIZE = 4096;
14+
bool hello = true;
15+
bool goodbye = false;
16+
bool cat = false;
17+
char *cat_fn = NULL;
18+
19+
char c;
20+
while ((c = getopt(argc, argv, "gt:c:h:u:e:")) != -1) {
21+
switch (c) {
22+
23+
case 'g': goodbye = true; hello = false; break;
24+
case 'c': cat = true; hello = false; cat_fn = optarg; break;
25+
26+
default:
27+
printf("Invalid argument.\n");
28+
return EXIT_FAILURE;
29+
}
30+
}
31+
32+
if (hello) {
33+
printf("Hello, world!\n");
34+
}
35+
if (goodbye) {
36+
printf("Goodbye!\n");
37+
}
38+
39+
if (cat) {
40+
FILE *fin = fopen(cat_fn, "r");
41+
if (!fin) {
42+
printf("Invalid file.\n");
43+
exit(EXIT_FAILURE);
44+
}
45+
char buffer[BUFFER_SIZE];
46+
while (fgets(buffer, BUFFER_SIZE, fin) != NULL) {
47+
printf("%s", buffer);
48+
}
49+
fclose(fin);
50+
}
51+
52+
// END_SOLUTION
53+
// BOILERPLATE: printf("Hello, CS 261!\n");
54+
return EXIT_SUCCESS;
55+
}
56+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* CS 261 PA0: Intro project
3+
*
4+
* Name:
5+
*/
6+
7+
#include "p0-intro.h"
8+
9+
int add_abs (int num1, int num2)
10+
{
11+
// BEGIN_SOLUTION
12+
return abs(num1) + abs(num2);
13+
// END_SOLUTION
14+
// BOILERPLATE: return 0;
15+
}
16+
17+
int factorial (int num)
18+
{
19+
// BEGIN_SOLUTION
20+
int fact = 1;
21+
for (int x = 2; x <= num; x++) {
22+
fact *= x;
23+
}
24+
return fact;
25+
// END_SOLUTION
26+
// BOILERPLATE: return 0;
27+
}
28+
29+
int sum_array (int *nums, size_t n)
30+
{
31+
// BEGIN_SOLUTION
32+
33+
int sum = 0;
34+
for (int i = 0; i < n; i++) {
35+
sum += nums[i];
36+
}
37+
return sum;
38+
39+
// END_SOLUTION
40+
// BOILERPLATE: return -1;
41+
}
42+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* CS 261: Intro project driver
3+
*
4+
* Name:
5+
*/
6+
7+
#include "p0-intro.h"
8+
9+
int main (int argc, char **argv)
10+
{
11+
// BEGIN_SOLUTION
12+
13+
const size_t BUFFER_SIZE = 4096;
14+
bool hello = true;
15+
bool goodbye = false;
16+
bool cat = false;
17+
char *cat_fn = NULL;
18+
19+
char c;
20+
while ((c = getopt(argc, argv, "gt:c:h:u:e:")) != -1) {
21+
switch (c) {
22+
23+
case 'g': goodbye = true; hello = false; break;
24+
case 'c': cat = true; hello = false; cat_fn = optarg; break;
25+
}
26+
}
27+
28+
if (hello) {
29+
printf("Hello, world!\n");
30+
}
31+
if (goodbye) {
32+
printf("Goodbye!\n");
33+
}
34+
35+
if (cat) {
36+
FILE *fin = fopen(cat_fn, "r");
37+
char buffer[BUFFER_SIZE];
38+
while (fgets(buffer, BUFFER_SIZE, fin) != NULL) {
39+
printf("%s", buffer);
40+
}
41+
fclose(fin);
42+
}
43+
44+
// END_SOLUTION
45+
// BOILERPLATE: printf("Hello, CS 261!\n");
46+
return EXIT_SUCCESS;
47+
}
48+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* CS 261 PA0: Intro project
3+
*
4+
* Name:
5+
*/
6+
7+
#include "p0-intro.h"
8+
9+
int add_abs (int num1, int num2)
10+
{
11+
// BEGIN_SOLUTION
12+
return abs(num1) + abs(num2);
13+
// END_SOLUTION
14+
// BOILERPLATE: return 0;
15+
}
16+
17+
int factorial (int num)
18+
{
19+
// BEGIN_SOLUTION
20+
int fact = 1;
21+
for (int x = 2; x <= num; x++) {
22+
fact *= x;
23+
}
24+
return fact;
25+
// END_SOLUTION
26+
// BOILERPLATE: return 0;
27+
}
28+
29+
int sum_array (int *nums, size_t n)
30+
{
31+
// BEGIN_SOLUTION
32+
33+
int sum = nums[0];
34+
for (int i = 1; i < n; i++) {
35+
sum += nums[i];
36+
}
37+
return sum;
38+
39+
// END_SOLUTION
40+
// BOILERPLATE: return -1;
41+
}
42+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* CS 261: Intro project driver
3+
*
4+
* Name:
5+
*/
6+
7+
#include "p0-intro.h"
8+
9+
int main (int argc, char **argv)
10+
{
11+
if (argc == 2 && strcmp(argv[1], "-g") == 0) {
12+
printf("Goodbye!\n");
13+
} else {
14+
printf("Hello, world!\n");
15+
}
16+
return EXIT_SUCCESS;
17+
}
18+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* CS 261 PA0: Intro project
3+
*
4+
* Name:
5+
*/
6+
7+
#include "p0-intro.h"
8+
9+
int add_abs (int num1, int num2)
10+
{
11+
// gets
12+
return abs(num1) + abs(num2);
13+
}
14+
15+
int factorial (int num)
16+
{
17+
return 0;
18+
}
19+
20+
int sum_array (int *nums, size_t n)
21+
{
22+
return -1;
23+
}
24+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* CS 261: Intro project driver
3+
*
4+
* Name:
5+
*/
6+
7+
#include "p0-intro.h"
8+
9+
int main (int argc, char **argv)
10+
{
11+
printf("Hello, world!\n");
12+
return EXIT_SUCCESS;
13+
}
14+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* CS 261 PA0: Intro project
3+
*
4+
* Name:
5+
*/
6+
7+
#include "p0-intro.h"
8+
9+
int add_abs (int num1, int num2)
10+
{
11+
return 0;
12+
}
13+
14+
int factorial (int num)
15+
{
16+
return 0;
17+
}
18+
19+
int sum_array (int *nums, size_t n)
20+
{
21+
return -1;
22+
}
23+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* CS 261: Intro project driver
3+
*
4+
* Name:
5+
*/
6+
7+
#include "p0-intro.h"
8+
9+
int main (int argc, char **argv)
10+
{
11+
printf("Hello, class!\n");
12+
return EXIT_SUCCESS;
13+
}
14+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* CS 261 PA0: Intro project
3+
*
4+
* Name:
5+
*/
6+
7+
#include "p0-intro.h"
8+
9+
int add_abs (int num1, int num2)
10+
{
11+
return 0;
12+
}
13+
14+
int factorial (int num)
15+
{
16+
return 0;
17+
}
18+
19+
int sum_array (int *nums, size_t n)
20+
{
21+
return -1;
22+
}
23+

ref/p0-intro/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int main (int argc, char **argv)
5050
}
5151

5252
// END_SOLUTION
53-
// BOILERPLATE: printf("Hello, CS 261!\n");
53+
// BOILERPLATE: printf("Hello, class!\n");
5454
return EXIT_SUCCESS;
5555
}
5656

ref/p0-intro/tests/itests.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# <TAG> used as the root for all filenames (i.e., "expected/$TAG.txt")
44
# <ARGS> command-line arguments to test
55

6-
run_test C_hello ""
6+
run_test D_hello ""
77
run_test C_goodbye "-g"
88
run_test B_cat "-c inputs/B_cat.txt"
99
run_test A_invalid_arg "-z"

0 commit comments

Comments
 (0)