San Jose State University

CS 49J - Programming in Java

Spring 2016

Homework 1/Prerequisite Quiz

  1. Prepare a plain text file aboutme.txt with the following information:
    Your name:
    Your student ID:
    Your major:
    Your preferred email address: 
    Check one: [ ] Undergraduate, [ ] Graduate, [ ] Open university 
    Repeating the class? [ ] Yes, [ ] No
    Programming language in which you are most competent (check only one): [ ] C++, [ ] C, [ ] Python, [ ] Java, other: ______
    Place where you took a programming course using that language: 
    Grade received:
    Time it took you to answer the two questions below:
    Did you ask anyone for help? [ ] Yes, [ ] No
    
  2. In your choice of C++, C, or Python, implement a function exchangesl that takes as argument an array of integers and modifies it so that the smallest and largest values are exchanged. You may assume that there is at least one element. If the largest value occurs more than once, exchange the first instance. If the smallest value occurs more than once, exchange the last instance.

    For example, if the array had elements 1 9 -1 4 -1 6 11 8 before the call, its elements would be 1 9 -1 4 11 6 -1 8 afterwards.

    If you choose C++, implement void exchangesl(vector<int>& a). Check your answer with CodeCheck.

    If you choose C, implement void exchangesl(int a[], int alen). Check your answer with CodeCheck.

    If you choose Python, implement exchangesl(a) where a is a list of integers. Check your answer with CodeCheck.

  3. In your choice of C++, C, or Python, implement a function splice that has two string arguments and that splices them together, alternating characters from both strings. For example, the result of splicing "Hello" and "World" is "HWeolrllod", and the result of splicing "me" and "you" is "myeou".

    In C++, implement string splice(string s, string t). Check your answer with CodeCheck.

    In C, implement void splice(char r[], const char s[], const char t[], int rlen). Check your answer with CodeCheck.

    In Python, implement splice(s, t) where s and t are strings. Check your answer with CodeCheck.

Important: The point of this assigment is for you to demonstrate that you already know how to program. This is not a class for students who can't yet program. Do not ask anyone for help. If you need to ask someone for help, or if it takes you longer than an hour to do this assignment, do not take this class. Take CS46A instead.

Important: For the programming problems, turn in the .signed.zip files that CodeCheck produces. (Click on the link labeled Download.) Do not turn in your .cpp, .c, or .py files without the CodeCheck results.

If you are already enrolled, submit the three files to Canvas.

If you are not yet enrolled, send an email to Cay.Horstmann@sjsu.edu with subject line

CS49J Prerequisite Quiz

empty body, and your three files attached.

You need to follow these instructions exactly, or you will not receive an add code.