7 Million Study Materials
From students who've taken these classes before
24/7 Access to Tutors
Personal attention for all your questions
Learn
93% of our members earn better grades
Rutgers | CS 101
 
 

54 sample documents related to CS 101

  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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.)
     
  • Rutgers CS 101
    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,
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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(
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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 <
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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 *
     
  • Rutgers CS 101
    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;
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    CS 101: Another Extra Homework Problem, Chapter 6 1. Consider the Num class below (this is the same as Listing 6.17 in Lewis public Num (int update){ value = up
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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.
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    CS 101, Prof. Loftin: Final Exam, May 11, 2009 Solutions 1. (8 pts) Write a method public static void printAsterisks(int[] ar) which accepts the parameter ar, an array of integers, and prints out for each value stored in the array at index index, a l
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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,
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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 :
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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; }
     
  • Rutgers CS 101
    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; } (
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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+\"\ \"+y); y = calc(2,y); System.out.println(y); } public static int cal
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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] = \'\\') break; if (
     
  • Rutgers CS 101
    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
     
  • Rutgers CS 101
    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
     
 
 
 
 
7,000,000 study materials • 24/7 tutors • earn better grades
Ask a tutor a question for CS 101
 
* 
Browse...