Earn Higher Grades With Instant Assignment Help.Ask Question!

C++ Programming
(5/5)

In this programming assignment, you will practice recursion. "All the world's a stage, and all the men and women merely players.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Introduction

In this programming assignment, you will practice recursion.

"All the world's a stage, and all the men and women merely players."

William Shakespeare

 

When we write, we use single quotation or double quotation marks to mark a quote. For a single quote, a pair of single quotation marks (') is used. For a double quote, a pair of double quotation marks (") is used. For processing textual documents (strings), we may need to match the quotation marks to find a quote. An sample application could be turnitin. Turnitin can exclude quotation marks when comparing documents.

In this assignment, we will be implementing recursive functions to process quotation marks, such as finding a quotation mark, matching quotation marks, etc. 

Tasks

You have to complete five tasks in this programming assignment. 
Since this is an assignment on recursion, you are NOT allowed to use any kind of loops. 
In addition, you are not allowed to use global variables or include any additional libraries. Othersie, you will receive ZERO marks for the assignment. 
You can add additional helper function(s) if necessary.

All following functions have 2 formal parameters:

  • line: specifies the input C String, which is a NULL-terminated char array.
  • start: specifies the starting index. It is always 0 when we call the function in main().

Practice Task (Not Graded)

Task 0 (0 points)

unsigned int recursive_strlen(const char line[], int start)

  • This function implements the strlen() function recursively.
  • Return: Number of characters in the string (line), excluding the NULL character at the end.

Hints

  • In the lecture notes of "Recursion", str_len() is implemented using a loop. You can use it for reference in thinking about how to convert the loop into recursion.
  • How can you process one char at each recursive call?
  • Where does the loop end? At which condition should the recursion end?
  • How does the loop move to the next character? How can you do the same using recursion?

Sample Input (line)

Return Value

(Empty)

0

A

1

COMP2011

8

 

Normal Tasks

Task 1 (15 points)

unsigned int count_dquotes(const char line[], int start)

  • This function counts the number of double quotation characters (") in the string (line).
  • Return: Number of double quotation characters.

Hint

  • This should be similar to Task 0.

Sample Input (line)

Return Value

(Empty)

0

COMP2011

0

"COMP2011"

2

 

Task 2 (15 points)

int find_first_dquote(const char line[], int start)

  • This function finds the index of the first double quotation character in the string (line).
  • Return:
    • ERROR (see the global constants in pa2.cpp) if no double quotation characters are found.
    • Index of the first double quotation character if otherwise.

Hints

  • Start by considering the case that double quotation characters are always found.
  • Then move on to consider the case when no double quotation characters are found.
  • What does it mean by reaching the end of string? What should you return?
  • How should you pass back this information?

Sample Input (line)

Return Value

(Empty)

ERROR

COMP2011

ERROR

"COMP2011"

0

Hello " World

6

 

Task 3 (20 points)

int count_chars_in_matched_dquote(const char line[], int start)

  • This function counts the number of characters inside all pairs of matching double quotation characters in the string (line).
  • Return:
    • ERROR if some double quotation characters are not matched.
    • Number of characters inside all pairs of matched double quotation characters if otherwise.

Definition of Matching Double Quotation Characters

  • Starting from the beginning of the string, a double quotation character is matched with the next closest double quotation character.
  • For example, consider the following string:

"Hello World", "COMP 2011"

    • The double quotation character before Hello is matched with the double quotation character after World.
    • The double quotation character before COMP is matched with the double quotation character after 2011.
    • All double quotation chacters are matched in this string. Returns 20.
  • Another example:

"Matched" Some"Quote

    • The double quotation chacters around Matched are matched.
    • But the double quotation characters between Some and Quote is not matched with any double quotation chacters. Returns ERROR.

Hint

  • What does it mean when a double quotation character is read?
  • Write a helper function.

Sample Input (line)

Return Value

(Empty)

0

COMP2011

0

"COMP2011"

8

Hello " World

ERROR

"Hello" "World"

10

" "Hello World" "

2

"A double quote: ""

ERROR

 

Challenging Tasks

Task 4 (25 points)

bool check_quotes_matched(const char line[], int start)

  • This function checks whether quotation characters (single and double quotation characters) in the string (line) are matched.
  • Return:
    • true if all quotation characters are matched, or no quotation characters are found.
    • false otherwise.

Definition of Matching Quotation Characters

  • Starting from the beginning of the string,
    • A single quotation character is matched with the next closest single quotation character.
    • A double quotation character is matched with the next closest double quotation character.
  • Exceptions:
    • Single quotation characters inside a pair of matched double quotation characters are ignored.
    • Double quotation characters inside a pair of matched single quotation characters are ignored.
  • Examples:

"Hello World", 'COMP 2011'

    • Double quotation characters around Hello World are matched.
    • Single quotation characters around COMP 2011 are matched.
    • Returns true.

"Hello 'World', ''' "

    • Double quotation characters around the whole string are matched.
    • All single quotation characters are inside a pair of double quotation characters, thus they are ignored.
    • All quotation characters are matched. Returns true.

'Hello"COMP'2011"

    • The single quotation character before Hello is matched with the single quotation character after COMP.
    • The double quotation character between Hello and COMP is ignored.
    • The double quotation character after 2011 is not matched with any double quotation characters.
    • Returns false.

Hint

  • Write two helper functions to handle:
    1. When a single quotation character is read.
    2. When a double quotation character is read.
  • These three functions should call each other.

Sample Input (line)

Return Value

(Empty)

true

COMP2011

true

'COMP2011'

true

Hello " World

false

" 'Hello World' "

true

"A single quote: '"

true

"A'A'A'A"

true

'"A""A"

false

 

Task 5 (25 points)

unsigned int length_of_longest_consecutive_dquotes(const char line[], int start)

  • This function finds the length of the longest consecutive sequence of double quotation characters in the string (line).
  • It returns the length of the longest consecutive sequence of double quotation characters.

Hint

  • Write a recursive helper function that takes additional parameters.

Sample Input (line)

Return Value

(Empty)

0

COMP2011

0

"COMP2011"

1

Hello " World

1

"""Hello World"""

3

AAAAAA""BBB

2

"""AAA""""""

6

"""""BBBBBBBBB"""

5

 

 

Attachments:
(5/5)

Related Questions

CSI 1420 Introduction to C Programming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Fu

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
568 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
661 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
797 Answers Hire Me