Skip to content

Instantly share code, notes, and snippets.

View jjlumagbas's full-sized avatar

JJ Lumagbas jjlumagbas

View GitHub Profile
@jjlumagbas
jjlumagbas / 11-final.c
Last active December 23, 2015 08:23
My solution to CMSC11 Final last 4 questions
#include <stdio.h>
void display(int arr[], int length) {
for (int i = 0; i < length; i++) {
printf("%d ", arr[i]);
}
printf("\n");
}
// 1

Misconception: "Waiting" if and while

Researchers have found that some students hold the following misconception: if statements "wait" for their conditional statement to become true. When that happens (at whichever point in the program), the corresponding block of code is executed.

For instance, consider this program:

size = 0
if size == 5:
>>>def twice(x):
... return x * 2
...
>>>
# Create a function that given a number,
# computes the value of the number times 2
# def twice(n):
# """
# (number) -> number
# Produce twice the value of the given number
# """
# The Kapehan coffee shop sells coffee
# beans at P850 per kilo plus the
# cost of shipping. Each order ships
# for P185 per kilo + P250 fixed cost
# per shipment for overhead.
# Write a function that calculates the
# cost of an order. 

# def order_cost(kilos):
# """
someFunction :: [a] -> [a]
someFunction (_:_:_:xs) = xs
someFunction _ = []
-- from Don Sanella
-- http://www.inf.ed.ac.uk/teaching/courses/inf1/fp/
searchRec :: Eq a => [a] -> a -> [Int]
searchRec xs y = srch xs y 0
where
srch :: Eq a => [a] -> a -> Int -> [Int]
srch [] y i = []
srch (x:xs) y i
| x == y = i : srch xs y (i+1)
public class AList {
private String[] items;
private int count;
public AList() {
items = new String[10];
count = 0;
}
public void add(String item) {
import junit.framework.TestCase;
/**
* A JUnit test case class.
* Every method starting with the word "test" will be called when running
* the test with JUnit.
*/
public class AListTest extends TestCase {
public class BoatRide implements Chargeable {
private double baseFare;
private double distance;
public BoatRide(double baseFare, double distance) {
this.baseFare = baseFare;
this.distance = distance;
}
public double cost() {