Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming help needed. Instructions The goal of this assignment is to understand the runtime and memory usage of common commands. You are provided with

C programming help needed.

Instructions

The goal of this assignment is to understand the runtime and memory usage of common commands.

You are provided with an incomplete C program. It uses five string functions. These are functions that are built into almost every high level language. You are going to implement them yourself. Then you are going to determine the runtime and memory usage of each function.

The primary goal of this assignment is to understand that as programmers it is important to know what built in tools do. The runtime of code we write is dependent on the code we use. If you dont have an idea of what that code is doing, you cannot estimate the complexity of your algorithms.

Provided Code

Provided with three files. Only need to make changes to one file. The others includes important instructions. Please review all provided files.

  • main.c - a collection of tests. You may not change this file
  • stringTools.h - prototypes for the functions assigned on the homework. You may not change this file. You must match the provided prototypes.
  • stringTools.c - the function definitions. You must implement the functions defined here. This is also where you will put your analysis.
    • I wrote code to implement it. https://1drv.ms/u/s!ArXxAGkuysamgsxguCNlJiYcGSUYew
  • Provides a zip file with main.c, stringTools.c, and stringTools.h >> https://1drv.ms/u/s!ArXxAGkuysamgsxf4e7AZv7WIymkyg

Replit will compile automatically. If you want to compile it manually the command would be:

gcc -o main main.c stringTools.c

Then you would excute it by typing ./main

Note that you only list the c files and not the h files in the compile command.

Functions

The functions you are doing to define are described in stringTools.h. This is just a summary.

  1. int length(char* str); - Determine the length of the string
  2. char* upper(char* str); - Convert all characters in str to uppercase
  3. int find(char* str, char target); - Find the position of the first appearance of target in str
  4. char* replace(char* str, char oldChar, char newChar); - Replace all appearances of oldChar with newChar in str
  5. bool lessThan(char* str1, char* str2); - Determine str1

Analysis

One you implement each function, you must do an analysis of the code you wrote.

For memory usage, determine the number of bytes uses for different parts of the function. You must determine the following:

  1. The number of bytes taken by all function inputs.
  2. The number of bytes in the return value.
  3. The number of bytes used to store local variables.
  4. The number of bytes allocated on the heap.

For the runtime analysis, put the number of times each operation is performed during execution. A Table template is provided in the files.

| Operation | Count | | --------- | ----- | | ? | ? |

Add as many rows as you need to write all the operations you used in the functions.

ExamplesExample 1 Welcome to String Tool Tester. Select Function to Test: 1.) length 2.) upper 3.) find 4.) replace 5.) lessThan 1 Testing length Enter A String: Hats Input Was: Hats Length Was: 4

Example 2 Welcome to String Tool Tester. Select Function to Test: 1.) length 2.) upper 3.) find 4.) replace 5.) lessThan 2 Testing upper Enter A String: Cats are nice pets. Input Was: Cats are nice pets. After Function Input Was: Cats are nice pets. Return value Was: CATS ARE NICE PETS.

Example 3 Welcome to String Tool Tester. Select Function to Test: 1.) length 2.) upper 3.) find 4.) replace 5.) lessThan 3 Testing find Enter A String: I am a long string with different words. Enter Character to find: r First Input Was: I am a long string with different words. Second Input was: r Return value Was: 14Example 4 Welcome to String Tool Tester. Select Function to Test: 1.) length 2.) upper 3.) find 4.) replace 5.) lessThan 4 Testing replace Enter A String: This string has some letters in it. Enter Character to find: t Enter Character to replace with: Q Input String: This string has some letters in it. Find Char: t Replace Char: Q After Function Input Was: This string has some letters in it. Return value Was: This sQring has some leQQers in iQ.

Example 5 Welcome to String Tool Tester. Select Function to Test: 1.) length 2.) upper 3.) find 4.) replace 5.) lessThan 5 Testing lessThan Enter first String: Cat Enter second String: Cats Input String 1: Cat Input String 2: Cats Return value Was: 1

Additional Rules

All functions must be prototyped above main and implemented below main.

In the stringTools.c I am allowed to make changes. The other two I am not allowed to make changes. When I tried compiling the program to run the tests he provided, I am getting a error message:

image text in transcribed
\f

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

Students also viewed these Programming questions

Question

Calculate expected utility as a way to evaluate risky outcomes.

Answered: 1 week ago

Question

Explain the process of biochemistry

Answered: 1 week ago