Return To CS 110 Home

Colour Theme   Font Size Options
 
   
   
   
Citation Builder

String Processing Exercise - Citation Builder


Video Summary: https://youtu.be/50GY8225yME


References are important in university, both for writing essays and writing code. Whenever you use examples in your own work, you are expected to cite where you get them from. If you and all your class were to reference the same example with no citation, even if you did not copy exactly or communicate with the other students, you would be at risk of being accused of plagiarism.

Citation makers are useful for making sure your citations are properly formatted and contain all the required information. Many citation makers work by simply having the user fill in a form, then using string processing to build the reference, adding or removing characters as needed. In this exercise, we will make a very simple one for ourselves.

Generally, science classes use APA format for web references:

Author Last Name, First Initial. (year published, month day). Title of article or page in italics. Site or organization name. URL.

For the sake of the exercise, we will use dd/mm/yyyy for the date format, which will result in numbers for the day and month, and leave out the URL. You also can't italicize console output.

Starting from this code:


  1. Use substr() to get the first initial
  2. Use find() to get the positions of the '/' characters, and divide the date into a day, month, and year string using substr()
  3. Use string concatenation to generate one string with all the fields and punctuation
  4. Output the finished string

When you are finished, you might have something that looks like this:

Blewett, D. (2022, 05 11). String Processing Exercise - Citation Builder. University of Regina.

Solution