[SOLVED] CSE1242 Assignment # 3

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon computer-programming-project3-vwafza.zip (777.2 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
Rate this product

In this homework, you will implement your own String data type using C structs. Each String is represented by a sequence of characters and should have a length property that shows the number of characters stored in that string (excluding the null character). Suppose that this struct can be used to represent only the strings with less than 50 characters. You should implement the following functions to operate on your String data type.

 int charAt(String *s, int index)
o This function should return the character stored at the location index. If there is

no such an index (either negative index value, or greater or equal to the length of the string), then return -1.

 String *concat(String *s1, String *s2)
o This function should concatenate the string pointed by s2 to the end of the string

pointed by s1, and return the address of the new string. You cannot use strcat or strncat functions of string.h library of C in that function.

 unsigned int strSearch(String *s1, String *s2)
o This function should scan the first string and return the length of initial segments that contain only the characters of the second string. If there is no such a segment, return 0. You cannot use strspn or strcspn functions of string.h library

of C in that function.

 unsigned int findScore(String *s1)
o This function should return a score by checking the given String. To calculate the

score, you will use the following table:

Letter

Value

A, E, I, O, U, L, N, R, S, T 1 D, G 2 B, C, M, P 3 F, H, V, W, Y 4 K5 J, X 8 Q, Z 10

o For example, the String is “hello” should be scored as 4 + 1 + 2 ∗ 1 + 1 = 8.

  •   Your program should continue to execute until the given word is either “exit” or “quit”. If the given word is “exit” or “quit”, your program should terminate. If the given word is “stat”, your program should print a two-line statistical report: the first line prints the total number of words the user has entered, and the second line prints the total number of alphabetic letters the user has entered. Note that we only count the 26 letters in the alphabet (either lower case or upper case). For example, if a user has entered the following string, i.e. “We love CSE1142 course a lot!!”, the following should be printed to screen after the user types “stat”:
      The number of words: 6
      The number of alphabetic letters: 19
    
  •   If the given word is not “stat”, “exit” or “quit”, then your program will continue to execute based on the user’s selection.
  •   You have to perform File I/O operations in this homework.

o All the user options will be given using an input file that is passed to your program

using command line arguments.
o All the outputs of your program must be printed to an output file that is passed to

your program using command line arguments.
o For example, suppose that “input.txt” and “output.txt” are given to your

program as command line arguments.
o Each line of the input file contains the related operations followed by the specified

options.
o For example, if a line is as follows:

       heLLo world:1,6

Here,
o “heLLo world” is the given string that we use.
o 1 represents that the operation is finding a char
o 6 represents the index for the searched char.
o The output for this option should be W, which will be added to a given output

file.

 The valid options given as the second argument (given after colon : ) can be o 1 for finding a char in the given index,

o 2forstringconcatenation,
o 3forstringsearch,
o 4forfindingthestringscore.

 If the required operation needs a third option (given after comma , ) it can be o An index for finding a char in the given string,
o A second string for string concatenation,
o A second string for string search.

  •   An operation may not require a third option (For example, finding the string score), in such a case, you can directly find the score of the string.
  •   Suppose that the input file contains the following lines:

    heLLo world:1,6
    Welcome to C:2,programming!
    welcome to marmara university!:3,mar We love CSE!!:4
    stat
    exit

  •   Then, the output file should contain the output of each operation as follows:
      W
      Welcome to C programming!
      7
      17
      The number of words: 14
      The number of alphabetic letters: 69
      Program ends. Bye
    

    Important Notes:

    •   The input and output files will be given as command line arguments to your program.
    •   The names of the files can be different than the given examples.
    •   The output file of your programs must be the same as the given example.
    •   Only parts selected from the selected questions will be graded. So if you send only one program,

      you might get a grade of 0 based on our evaluation.

    •   Please be sure that your programs should run properly on both your computer and a different

      computer.

      Submission Instructions:

      Please submit your source file using filename YourNumberHW3.c (ex: 150713852HW3.c) to Canvas system (under Assignments tab). If you want to submit multiple .h/.c files, then submit

them in

Notes: 1.

2. 3. 4. 5.

a single zip file.

  • computer-programming-project3-vwafza.zip