CSE 1311 - Section 2 - Assignments - Assignment 6

Due date: Wednesday, March 10, 2010, 11:55pm.


Task 1 (20 points)

Write a program called task1.c or task1.cpp, that behaves as follows: For full credit, you should implement a function ... repeat_letters(... A, ... B), that takes as input a string A and an integer B, and returns a new string C, obtained by repeating B times every letter of A. Examples:


Task 2 (20 points)

Write a program called task2.c or task2.cpp, that behaves as follows: For full credit, you should implement a function ... put_dot(... A), that takes as input a string A, and returns a new string C, that is like A, with an extra period at the end. Examples:


Task 3 (20 points)

Write a program, in a file called task3.c or task3.cpp, that behaves as follows:

For full credit, you should implement a function ... put_dots(... A), that takes as input a string A, and returns a new string C, that is like A, with a period inserted after each character of A. Examples:


Task 4 (20 points)

Mr. Bugs wants to write a simple program that creates a string "Hello" and prints it. Unfortunately, the program does not print the string correctly. Can you find and correct the problem? Note that it is not sufficient to provide code that behaves correctly, you must specify exactly what was wrong with Mr. Bugs' code. Include the answer in your answers.doc file.

Here is the program that Mr. Bugs wrote:

#include <stdio.h>

int main()
{
  char * my_string = (char *) malloc(sizeof(char) * 5);

  my_string[0] = 'h';
  my_string[1] = 'e';
  my_string[2] = 'l';
  my_string[3] = 'l';
  my_string[4] = 'o';
  
  printf("my_string = %s\n", my_string);
}


Task 5 (20 points)

Mr. Bugs tried another approach to get the program of task 4 to work correctly. Unfortunately, the new program still does not print the string correctly. Can you find and correct the problem? Note that it is not sufficient to provide code that behaves correctly, you must specify exactly what was wrong with Mr. Bugs' code.

Here is the program that Mr. Bugs wrote:

#include <stdio.h>

int main()
{
  char * my_string = (char *) malloc(sizeof(char) * 6);

  my_string[0] = 'h';
  my_string[1] = 'e';
  my_string[2] = 'l';
  my_string[3] = 'l';
  my_string[4] = 'o';
  my_string[5] = '0';
  
  printf("my_string = %s\n", my_string);
}


How to submit

Submisions are only accepted via WebCT. The submission should include your C or C++ source files, and answers.doc. Do not submit entire project directories, or anything else except for the .c and .cpp files and the answers.doc file.

Your answers.doc file should be a single Microsoft Word file that includes:

Make sure that your answers.doc file is easy to parse, and that it is easy for us to figure out which part corresponds to which task. Feel free to use headings such as "start of copy of task1.c".

We try to automate the grading process as much as possible. Not complying precisely with instructions causes a significant waste of time during grading, and thus points will be taken off for failure to comply, and/or you may receive a request to resubmit.

Submission checklist