CS 101
  • 2 Pages extra_hw
    Extra_hw

    School: Rutgers

    CS 101: Homework Problems 1. What is the output (to the screen)? public class Question1{ public static void main (String[] args){ int x = 5, y; y = calc(x,4); System.out.println(x+"\n"+y); y = calc(2,y); System.out.println(y); } public static int cal

  • 2 Pages solquiz3
    Solquiz3

    School: Rutgers

    CS101: Quiz #3 ANSWERS 1. Consider the following program: #include<iostream.h> void main() { int a,b; cin > a > b; if (a > b){ if (a > 0) cout < a; else cout < 2; } else cout < b; } For each of the following inputs, give the output: Input 12 21 -2

  • 2 Pages solquiz2
    Solquiz2

    School: Rutgers

    CS101: Quiz #2 Name: SOLUTION 1. For each of the following arithmetic expressions, give its value and check off whether the value is integer or floating-point. The first row is filled in for you: Expression 1+2 2.+3*4 15 / 2 15 % 2 15 / 2.0 6*3%7 V

  • 1 Page quiz4sol
    Quiz4sol

    School: Rutgers

    CS 101: Quiz #4, February 18, 2009, SOLUTIONS 1. Write a for loop to print the odd numbers from 1 to 99 (inclusive). Solution: for (int i=1; i<100; i+=2) System.out.println(i); 2. What is the output of the following Java code fragment? int num = 0, m

  • 7 Pages test2sol
    Test2sol

    School: Rutgers

    CS 101: Test 2: April 6, 2009 SOLUTIONS 1. (10 pts) Mark each of the following logical expressions as either true or false. You can assume we have declared int x=2, y=2, z=4; boolean k = false; Expression true false (x>=1) | k X (z=y*x) X (z<5) | (y

  • 5 Pages soltest3a
    Soltest3a

    School: Rutgers

    TEST 3, CS 101, FRIDAY, APRIL 16, 2004 (1) What is the output? #include<iostream.h> void print(int[][3]); void print_warp(int[][3]); void main(){ int a[2][3], i, j; for (i=0; i<2; i+) for (j=0; j<3; j+) a[i][j] = i + 2*j + 1; print(a); cout < endl; p

  • 4 Pages practicetest2
    Practicetest2

    School: Rutgers

    CS 101: Practice Questions for Test 2 1. Write a Java application which prompts the user to enter integers from the screen until the end of le character is entered, computes the sum of the integers, and prints this sum to the screen. 2. If a triangle

  • 3 Pages quiz7sol
    Quiz7sol

    School: Rutgers

    CS101: Quiz #7, March 25, 2009 Name: 1. Put the output to the screen in the box below. public class Question{ private static final int MAX = 5; public static void main (String[] args){ System.out.println(MAX); System.out.println(ff(3); System.out.pri

  • 7 Pages practicetest2sol
    Practicetest2sol

    School: Rutgers

    CS 101: Practice Questions for Test 2 SOLUTIONS 1. Write a Java application which prompts the user to enter integers from the screen until the end of le character is entered, computes the sum of the integers, and prints this sum to the screen. Soluti

  • 3 Pages practicetest1
    Practicetest1

    School: Rutgers

    CS 101: Practice Questions for Test 1 1. Write a Java application which prompts the user to enter 15 integers, then computes the sum, and then prints the sum to the screen. 2. Recall the Pythagorean Theorem says that if a, b are the lengths of two ed

  • 1 Page samplequiz3
    Samplequiz3

    School: Rutgers

    CS101/ Sample Quiz #3 3. Write a code fragment to print the message OK if the integer variable x satisfies 10 < x 20 and which prints not OK if not. NAME: 1. Consider the following program #include <iostream.h> void main(){ int a, b; cin > a > b;

  • 2 Pages solquiz6
    Solquiz6

    School: Rutgers

    CS101/Quiz/# 6, Wednesday, April 28, Answers 1. What is the output? #include<iostream.h> char* split(char*); void main(){ char phrase[] = "One, two, three, four.", *rest; rest = split(phrase); cout < phrase < endl < rest < endl; } char* split(char *

  • 5 Pages test1b_sol
    Test1b_sol

    School: Rutgers

    TEST 1, MONDAY, FEBRUARY 16, 2004 ANSWERS (1) Consider the following program: #include <iostream.h> void main() { int a=2, b=1; a+; b += a; if (b=4) a-; else a +=2; cout < a < endl < b < endl; } Put the output of the program in the space below: 2 4

  • 8 Pages practicetest3sol
    Practicetest3sol

    School: Rutgers

    CS 101: Practice Questions for Chapter 6 and 7 SOLUTIONS 1. Modify the class Student below to add a member num which counts the number of Student objects which have been instantiated. (Hint: should num be static or not?) Solution: public class Studen

  • 1 Page more_extra_hw
    More_extra_hw

    School: Rutgers

    CS 101: Another Extra Homework Problem For the following problem, consider the Account class, from Lewis & Loftus, Listing 4.4. What is the output (to the screen)? 1. What is the output (to the screen)? public class AccountDriver{ public static void

  • 2 Pages quiz2
    Quiz2

    School: Rutgers

    CS101/Sample Quiz #2/ 1. Circle the valid C+ identifiers in the following list (each line contains one possible identifier): abc123 a_b_c a2 2a a Very Long Identifier aVeryLongIdentifier int 2. For each of the following arithmetic expressions, give

  • 1 Page quiz11sol
    Quiz11sol

    School: Rutgers

    CS101: Quiz #11, April 29, 2009 SOLUTIONS 1. Design and implement an application that reads an arbitrary number of integers, each in the range from 0 to 50 inclusive, from the user, and then counts how many occurrences of each are entered. After all

  • 2 Pages quiz10sol
    Quiz10sol

    School: Rutgers

    CS101: Quiz #10, April 22, 2009 SOLUTIONS 1. (a) Write a method called average that accepts two integer parameters and returns their average as a floating point value. Solution: public static double average(int m, int n){ return (double) (m+n)/2; } (

  • 1 Page quiz6sol
    Quiz6sol

    School: Rutgers

    CS 101: Quiz #6, March 11, 2009, SOLUTION 1. Write a method called random100 that returns a random integer in the range of 1 to 100 inclusive. Solution: public int random100(){ return (int)(Math.random()*100) + 1; }

  • 1 Page quiz2sol
    Quiz2sol

    School: Rutgers

    CS 101: Quiz #2, February 4, 2009 SOLUTIONS 1. What is the value of each of the following expressions? (a) 15 + 7 * 3 Solution: 15 + 7 * 3 is 15 + 21 is 36. (b) (15 + 7) * 3 Solution: (15 + 7) * 3 is 22 * 3 is 66. (c) 27 % 5 + 7 % 3 Solution: 27 % 5

  • 5 Pages practicetest3
    Practicetest3

    School: Rutgers

    CS 101: Practice Questions for Chapter 6 and 7 1. Modify the class Student below to add a member num which counts the number of Student objects which have been instantiated. (Hint: should num be static or not?) public class Student{ private String na

  • 1 Page solquiz4
    Solquiz4

    School: Rutgers

    CS101, Quiz 4 1. What is the output of the following program? #include <iostream.h> int f(int x, int y); void main(){ int a=3, b=4, c=2; cout < a < endl; cout < b < endl; cout < c < endl; a += f(c,b); cout < a < endl; cout < b < endl; cout < c < end

  • 2 Pages samplequiz6
    Samplequiz6

    School: Rutgers

    CS101/Sample Quiz/# 6 1. What is the output? #include <iostream.h> #include <cstring> void main(){ char s[30]="A rose is a rose is a rose. "; char words[25][30], *new_word = s; int num_words=0, i, j; for (i=0; i<30; i+){ if (s[i] = '\0') break; if (

  • 2 Pages quiz9sol
    Quiz9sol

    School: Rutgers

    CS101: Quiz #9, April 15, 2009 SOLUTION 1. Use the RationalNumber class which we discussed in class and in the book, to write a driver class which allows the user to enter many rational numbers (numerator first, then denominator), until the end of fi

  • 1 Page quiz8sol
    Quiz8sol

    School: Rutgers

    CS101: Quiz #8, April 1, 2009 SOLUTIONS 1. Consider the following declarations: int value1 = 5, value2 = 10; boolean done = true; What is the value (true or false) of each of the following boolean expressions? (a) value1 < value2 / 2 Solution: false,

  • 2 Pages samplequiz5
    Samplequiz5

    School: Rutgers

    CS101/Sample Quiz/# 5 1. For the following program, ll in the values of the array a at the position indicated in the program. #include <iostream.h> void main(){ int a[5]; for (int i=0;i<5;i+) a[i]=i*i; a[0] 0 a[1] 1 a[2] 4 a[3] 9 a[4] 16 for (int i

  • 2 Pages solquiz5
    Solquiz5

    School: Rutgers

    CS101/Quiz/# 5, Wednesday, April 7 1. What is the output? #include<iostream.h> class Vec{ private: double x, y, z; public: void init(); void print_vec(); Vec rotate(); }; void Vec:init(){ x = 5; y = 2; z = 4;} void Vec:print_vec(){ cout < "(" < x <

  • 1 Page samplequiz4
    Samplequiz4

    School: Rutgers

    CS101, Sample Quiz 4 1. What is the output of the following program? #include <iostream.h> int f(int x, int y); void main(){ int a=1, b=2, c=3; cout < a < endl; cout < b < endl; cout < c < endl; c = f(a,b); cout < a < endl; cout < b < endl; cout < c

  • 2 Pages sample10
    Sample10

    School: Rutgers

    1. A solution to PP 7.8 This solution to PP 7.8, as discussed in class, can serve as a model for Program 10. 2. Problem PP 7.8 Design and implement an application that reads a sequence of up to 25 pairs of names and postal (ZIP) codes for individuals

  • 2 Pages probs
    Probs

    School: Rutgers

    CS 101: Extra Problems, Chapter 7 1. What is the output to the screen? public class Prob{ public static void main(String[] args){ int[] b = new int[10]; int c = 27; for (int i=0; i<10; i+) b[i] = i*i; change(b,c); System.out.println(c); for (int x :

  • 1 Page program6
    Program6

    School: Rutgers

    1. Program 6 Instructions, CS101, Prof. Loftin Write a program that reads in doubles from standard input until the end of file (when two <CONTROL>D's are entered). The program should then print the maximum value that was input to the screen. You will

  • 2 Pages program9
    Program9

    School: Rutgers

    1. Program 9 Instructions, CS101, Prof. Loftin Write a class ArrayStats which has two public static methods public static double mean (double[] ar) / returns the mean of the values in the array public static double sd (double[] ar) / returns the stan

  • 4 Pages program10
    Program10

    School: Rutgers

    1. Program 10 Instructions, CS101, Prof. Loftin Write a program to manage bank accounts. Each account has an integer id and a current balance (double). The input consists of lines containing the account id and the amount to be posted to the account.

  • 1 Page ex_ch6
    Ex_ch6

    School: Rutgers

    CS 101: An Extra Homework Problem, Chapter 6 1. Using the RationalNumber class discussed in class and in Lewis & Loftus, Listing 6.4, write a driver class which allows the user to enter many rational numbers (numerator rst, and then denominator), unt

  • 2 Pages ex2_ch6
    Ex2_ch6

    School: Rutgers

    CS 101: Another Extra Homework Problem, Chapter 6 1. Consider the Num class below (this is the same as Listing 6.17 in Lewis & Loftus, with the addition of the getValue method). public class Num{ private int value; public Num (int update){ value = up

  • 2 Pages program5
    Program5

    School: Rutgers

    1. Program 5 Instructions, CS101, Prof. Loftin Implement the Diamond class. The Diamond class should contain the following methods: Diamond(int n) void printOut() / Constructor, for a Diamond object of side-length n / Prints the Diamond shape to the

  • 3 Pages Project2
    Project2

    School: Rutgers

    Program 2, CS 101, Prof. Loftin Due Monday, February 23, 2004 The problem A moving car is being braked at a constant acceleration. Compute whether or not the car has come to a complete halt. Read v0 (the initial velocity), a (the acceleration-which i

  • 1 Page program3
    Program3

    School: Rutgers

    1. Program 3 Instructions, CS101, Prof. Loftin The sum of the squares of the first 10 positive integers is 12 + 22 + + 102 = 385. On the other hand, the square of the sum of the first 10 positive integers is (1 + 2 + + 10)2 = 552 = 3025. Theref

  • 1 Page program1
    Program1

    School: Rutgers

    1. Program 1 Instructions, CS101, Prof. Loftin Write a Java program which prints out the message "The only thing to fear is fear itself," is one of Franklin Roosevelt's best-known quotations. The first line of your output should be properly indented,

  • 2 Pages program7
    Program7

    School: Rutgers

    1. Program 7 Instructions, CS101, Prof. Loftin Write a class Planet.java which contains the following public methods: Planet (String n, double r, double m) String getName() double getRadius() double getMass() double computeWeight(double w) Here const

  • 1 Page quiz3sol
    Quiz3sol

    School: Rutgers

    CS 101: Quiz #3, February 11, 2009, Solutions 1. Write a Java application that reads two oating point numbers and prints their sum, dierence, and product. import java.util.Scanner; public class DoubleMath{ public static void main (String[] args){ dou

  • 4 Pages test1sol
    Test1sol

    School: Rutgers

    CS101, TEST 1, MONDAY, MARCH 2, 2009, PROF. LOFTIN SOLUTIONS (1) (10 pts) What is the output of the following program? public class FirstProgram{ public static void main(String[] args){ int a=1, b=2; a+; b += a; if (b=4) a+; else a-; System.out.prin

  • 5 Pages soltest3b
    Soltest3b

    School: Rutgers

    TEST 3, CS 101, MONDAY, APRIL 19, 2004 (1) What is the output? #include<iostream.h> void print(int[][3]); void print_opp(int[][3]); void main(){ int a[2][3], i, j; for (i=0; i<2; i+) for (j=0; j<3; j+) a[i][j] = (i+1)*(j+2); print(a); cout < endl; pr

  • 1 Page quiz5sol
    Quiz5sol

    School: Rutgers

    CS 101: Quiz #5, February 25, 2009, SOLUTIONS 1. Assuming that a Random object has been created called generator, what is the range of the result of each of the following expressions? (a) generator.nextInt(20) Solution: 0 to 19 (b) generator.nextInt(

  • 6 Pages practicetest1sol
    Practicetest1sol

    School: Rutgers

    CS 101: Practice Questions for Test 1, SOLUTIONS 1. Write a Java application which prompts the user to enter 15 integers, then computes the sum, and then prints the sum to the screen. import java.util.Scanner; public class SumInts{ public static void

  • 5 Pages test1a_sol
    Test1a_sol

    School: Rutgers

    TEST 1, FRIDAY, FEBRUARY 13, 2004 ANSWERS (1) Consider the following program: #include <iostream.h> void main() { int a=1, b=2; a+; b += a; if (b=4) a+; else a-; cout < a < endl < b < endl; } Put the output of the program in the space below: 3 4 1

  • 8 Pages sfinalq
    Sfinalq

    School: Rutgers

    SAMPLE QUESTIONS ON CHAPTERS 12 AND 13, CS 101 (1) Write a function void lower_all(char s[]) which takes the C-string s and converts all of the uppercase letters in s to their lowercase version. (The rest of the characters in s should be unchanged.)

  • 7 Pages test2a_sol
    Test2a_sol

    School: Rutgers

    TEST 2, CS 101, SECTION 2 MONDAY, MARCH 22, 2004 ANSWERS (1) Consider the following function declaration: int f(int); The function f should take as input an integer n and return the value 0 if n <= 0. If n > 0 and n is odd, then f should return the

  • 7 Pages sampletest3
    Sampletest3

    School: Rutgers

    SAMPLE TEST 3, CS 101 (1) For each integer n, an is defined to be 1 if n 1, and is defined by the formula an = 2an-1 + 1 for n > 1. Write a function int a(int n) whose output is an . To implement this function, YOU MUST USE A RECURSIVE FUNCTION CALL

  • 7 Pages test2b_sol
    Test2b_sol

    School: Rutgers

    TEST 2, CS 101, SECTION 3 WEDNESDAY, MARCH 24, 2004 ANSWERS (1) Consider the following function declaration: int sum(int); The function sum should take as input an integer n and return the value 0 if n <= 0. If n > 0, the value returned should be the

  • 8 Pages sample_test2
    Sample_test2

    School: Rutgers

    PRACTICE TEST 2, CS 101 (1) Consider the following function declaration: int sum(int); The function sum should take as input an integer n and return the value 0 if n <= 0. If n > 0, the value returned should be the sum 1+2+3+.+(n-1)+n of the rst n po

  • 6 Pages sampleTest1
    SampleTest1

    School: Rutgers

    CS101/Sample Test #1/ 1. Circle the valid C+ identifiers in the following list (each line contains one possible identifier): abx& XY_s f2 double 8th_number eighth_number eighth number 2. For each of the following arithmetic expressions, give its val

  • 1 Page program2
    Program2

    School: Rutgers

    1. Program 2 Instructions, CS101, Prof. Loftin Write a Java program to convert an integer number of seconds into hours, minutes, and seconds. Your program should prompt the user to enter the number of seconds, and then print out the conversion. For e

Back to course listings