strlen(): strlen() counts the number of characters in a cstring. The algorithm works by looking at...

strlen():

strlen() counts the number of characters in a cstring. The algorithm works by looking at each character in the cstring, counting as it goes. It stops looking at characters when it encounters a null terminator ‘\0’.

Here is my implementation of the strlen() function. You will need to write and test my solution and your own solution.

int profStrLen( char *str ) {
  char *endOfStr = str;
  while( *endOfStr != '\0' ) {
     endOfStr++;
  }
  return (int)(endOfStr - str);
}

Make sure you understand how my implementation is working before creating your own. Then, you can write your own implementation. For your implementation, do not use pointer arithmetic to solve it - use array notation and a counter instead. Here is the prototype for your function.

int stuStrLen( char * );

strcpy():

strcpy() copies the contents of the second char* into the memory of the first char*. The algorithm works by looking at each character in the second char* and copies that into the first char*. Because we are dealing with cstrings, the copying process will stop when the ‘\0’ is reached in the second char*.

Here’s my implementation. Again, you will need to write and test my solution and your own.

char *profStrCpy( char *str1, char *str2 ) {
  char *dest = str1;
  while( *str2 != '\0' ) {
    *str1 = *str2;
    str1++;
    str2++;
  }
  *str1 = ‘\0’;
  return dest;
}

Make sure you understand how my implementation is working before creating your own. Then, you can write your own implementation. For your implementation, do not use pointer arithmetic to solve it - use array notation and a counter instead. Here is the prototype for your function.

char *stuStrCpy( char *, char * );

strcat():

strcat() copies the contents of the second char* into the memory of the first char* like strcpy(), but it copies the values in the second char* to the end of the first char*. The algorithm works by looking at each character in the first char* until the ‘\0’ is found. Then, it looks at each character in the second char* and copies that into the first char*’s current location. As it does this, it increments the position in each char* until the ‘\0’ is found in the second char*.

Here’s my implementation. Again, you will need to write and test my solution and your own.

char *profStrCat( char *str1, char *str2 ) {
  char *dest = str1;
  while( *str1 != '\0' ) {
    str1++;
  }
  while( *str2 != '\0' ) {
    *str1 = *str2;
    str1++;
    str2++;
  }
  *str1 = ‘\0’;
  return dest;
}

Make sure you understand how my implementation is working before creating your own. Then, you can write your own implementation. For your implementation, do not use pointer arithmetic to solve it - use array notation and a counter instead. Here is the prototype for your function.

char *stuStrCat( char *, char * );

Intermediate cstring function

Now that you have worked through many of the cstring functions. I want you to implement the following functions on your own. I will provide an overview of the algorithm, but I will not provide you with an implementation from me. You will need to write and test this function.

strcmp():

strcmp() compares strings lexicographically. It returns a negative value if the first string occurs lexicographically before the second string. It returns a positive value if the first string occurs lexicographically after the second string. And, it returns zero if the two strings are equivalent. Make sure you call attention to the return of strcmp(). The return of zero instead of a non-zero is a common source for errors involved with cstring processing.

The algorithm for strcmp() works by subtracting each character as it iterates through each cstring stopping when the result of the subtraction is nonzero or a ‘\0’ is found in one of the strings. We will return the difference between the two characters.

You will need to write and test your solution. Here is your prototype.

int stuStrCmp( char *, char * );

Everybody likes a mystery

Here is a function of code that is labeled mystery. Type in the code and describe in the comments what the function does algorithmically and tell me what you think the function is named.

int mystery( char *str ) {
  char *str2 = str;
  long pos;
  int result = 0;

  while( *str2 != '\0' ) {
    str2++;
  }
  pos = str2 - str - 1;

  for( int count = 1; pos >= 0; pos --, count *= 10 ) {
    if( str[pos] == ‘-') {
      result *= -1;
    } else {
      result += (str[pos] - '0') * count;
    }
  }
  return result;
}

main.cpp

#include <iostream>

using namespace std;

int profStrLen( char * );
int stuStrLen( char * );
char *profStrCpy( char *, char * );
char *stuStrCpy( char *, char * );
char *profStrCat( char *, char * );
char *stuStrCat( char *, char * );
int stuStrCmp( char *, char * );
int mystery( char * );

int main() {
// type all testing code here
return 0;
}

// implement the functions here

In: Computer Science

give short description of each phase of the cardicac cycle where is blood going to and...

give short description of each phase of the cardicac cycle
where is blood going to and from?
b. does a valve open or close at the beginning or end of the phase?
c. what does volume in the ventricles look like? (eg: getting higher, same, getting lower)
d. Are the ventricles contracting or relaxing?

In: Biology

Management Science Bank is the only bank in the small town of Sto Thomas. On a...

Management Science Bank is the only bank in the small town of Sto Thomas. On a typical Friday, an average of 10 customers per hour arrive at the bank to transact business. There is one teller at the bank, and the average time required to transact business is 4 minutes. It is assumed that service times may be described by the exponential distribution. A single line would be used, and the customer at the front of the line would go to the first available bank teller. If a single teller is used, find:
a.) The average time in the line.
b.) The average number in the line.
c.) The average time in the system.
d.) The average number in the system.
e.) The probability that the bank is empty.
f.) Management Science Bank is considering adding a second teller (who would work at the same rate as the first) to reduce the waiting time for customers. She assumes that this will cut the waiting time in half. If a second teller is added, find the new answers to parts (a) to (e).

In: Operations Management

What is the ultimate fate of the digested chicken and rice? What was the initial biological...

What is the ultimate fate of the digested chicken and rice? What was the initial biological structure of the nutritional components first consumed (example proteins breaking down to their simpler components) and what are the resulting products resulting from digestion that are now ready and available for use by the body for energy and homeostasis?

In: Chemistry

how do corporations benefit from government regulation? *refer to Dean Baker's THE CONSERVATIVE NANNY STATE*

how do corporations benefit from government regulation?

*refer to Dean Baker's THE CONSERVATIVE NANNY STATE*

In: Economics

##Notice: write in HLA code . . Create an HLA Assembly language program that prompts for...

##Notice: write in HLA code

.

.

Create an HLA Assembly language program that prompts for a single integer value from the user and prints an boxy pattern like the one shown below. If the number is negative, don't print anything at all.

.

Here are some example program dialogues to guide your efforts:

.

Feed Me: 5
55555
5 5
5 5
5 5
55555

Feed Me: -6

Feed Me: 3
333
3 3
333

.

In an effort to help you focus on building an Assembly program, I’d like to offer you the following C statements matches the program specifications stated above. If you like, use them as the basis for building your Assembly program.

.

SAMPLE C CODE:
------------------------

int i, n, j;
printf( "Feed Me:" );
scanf( "%d", &n );

for (i=1; i<=n; i++) {
if (i == 1 || i == n) { // first or last row
for (j = 1; j <= n; j++) {
printf( "%d", n );
}
printf( "\n" );
}
else { // internal rows of the box
printf( "%d", n );
for (j = 1; j <= n-2; j++) {
printf( " " );
}
printf( "%d", n );
printf( "\n" );
}

}

.

##Answer the questinon in HLA Assembly language program.

In: Computer Science

The water used in this experiment is sparged with nitrogen to remove any dissolved oxygen. The...

The water used in this experiment is sparged with nitrogen to remove any dissolved oxygen. The proton-coupled reduction of oxygen is shown in the following half reaction:

O2 + 4H+ +4e- --> 2H2O

1) Explain why sparging a solution with N2 to remove dissolved oxygen is an equilibrium process.

2) Using the half reaction above, write the balanced equation for the reaction of ascorbic acid with oxygen. Show your work.

3) If you didn’t know whether or not O2 is capable of oxidizing ascorbic acid, how would you determine this by consulting data? What data would you consult and what would you look for?

In: Chemistry

Topic: Schizophrenia 1. Review the readings on schizophrenia, DSM-V criteria and briefly describe schizophrenia, and current...

Topic: Schizophrenia

1. Review the readings on schizophrenia, DSM-V criteria and briefly describe schizophrenia, and current understanding of the disorder.

2. Conduct a literature search and address one of the following questions in a brief essay:

a) What is the relationship (if any) between violence and schizophrenia?

b) What role, if any, does stigma play in help seeking, treatment, and recovery?

In: Psychology

Calculate the frequency in Hz of a typical green photon emitted by the Sun. What is...

  1. Calculate the frequency in Hz of a typical green photon emitted by the Sun. What is the physical interpretation of this (very high) frequency? (That is, what is oscillating?)

In: Physics

In the previous question, you designed a simple algorithm to create a class list application. In...

In the previous question, you designed a simple algorithm to create a class list application. In this question, you
will implement the same application in Java. To do this, you will need a working version of a Student ADT, a List
ADT, and the List Iterator. You may start with your own Student ADT, or you can start from the solutions to
Assignment 2. You will be given a working version of a List ADT.
Recall that your application does the following:
• Create a class list of students
• Display every Student record in the class list to the console.
• Give every student a bonus mark on the final exam. It does not matter how much of a bonus you give.
• Display every Student record in the class list to the console, to show the changes to the records.
You must store Student objects in a List, using the given List ADT.
You are to use the List Iterator for any task that requires looking at every element in a list (the last two items
above).
Here’s a guide for you to help you manage this task.
1. Download the BasicLinkedList.java and List.java files from Moodle.
2. Obtain the StudentADT.java and Student.java files from either your solution or the model solution of assignment
3. Create a new application class called ClassListApp.java, that contains a main method. Make sure that you
include import java.util.*; on the top of the file.
4. Take your design for Exercise 1, and copy it into ClassListApp.java, as comments. Implement the design in
steps (not all at once). Every time you have a step implemented, compile and test.

Here are the java source file already given

List.java

import java.util.Iterator;

/**
* Defines the interface to a list collection.
* The implementation of the list is hidden.
*
*/
public interface List<E> extends Iterable<E>
{
  
/**
Pre:
Post: the list is unchanged.
* Return: true if this list contains no elements; false otherwise
*/
public boolean isEmpty();
  
  
/**
Pre:
Post: the list is unchanged.
* Return: the number of elements in this list.
*/
public int size();
  
  
/**
* Check if an element exists in the list
Pre:
Post: the list is unchanged.
Return: true if the specified element is found in this list and
false otherwise. Throws an EmptyCollectionException if the list
is empty.
*/
public boolean contains (E targetElement);
  
/**
Deletes the first element in this list and returns a reference
to it. Throws an EmptyCollectionException if the list is empty.
Pre:
Post: the first element is removed from the list
Return: a reference to the removed element
*/
public E deleteHead();
  
/**
Removes the last element in this list and returns a reference
to it. Throws an EmptyCollectionException if the list is empty.
Pre:
Post: the last element is removed from the list
Return: a reference to the removed element
*/
public E deleteTail();
  
/**
Removes the first instance of the specified element from this
list and returns a reference to it. Throws an EmptyCollectionException
if the list is empty. Throws a ElementNotFoundException if the
specified element is not found in the list.
Pre: targetElement :: E, the target element to be removed
Post: the element is removed from the list
Return: a reference to the removed element
*/
public E deleteElement(E targetElement);


/**
Insert a new node to the head of the list.
Pre: item :: E, content in the new node
Post: new node is inserted to the head of the list
Return: nothing
*/
public void insertHead(E item);
  
/**
Insert a new node to the end of the list.
Pre: item :: E, content in the new node
Post: new node is inserted to the end of the list
Return: nothing
*/
public void insertTail(E item);
  
  
/**
Insert a new node at a specific position in the list.
Pre: item :: E, content in the new node
position :: the position of the new node
Post: new node is inserted at position in the list
Return: nothing
*/
public void insertAtPosition (E item, int position);
  
  
/**
Retrive the element at a specific position in the list.
Pre: position :: Integer, a position in the list
Post: the list is unchanged
Return: the element at the position
*/
public E get(int position);
  
  
  
/**
* Useful method for pretty print for atomic data
Pre:
Post: the list is unchanged.
Return: Returns a string representation of this list.
*/
public String toString();
  
  
/**
* Returns an iterator for the elements in this list.
*
* @return an iterator over the elements in this list
*/
public Iterator<E> iterator();
  
  }

Student.java

/**
* Defines the interface to the student ADT.
*
*/
public interface Student {

/**
displayStudentRecord()
Pre:
Post: displays Student info
Return: nothing
*/
public void displayStudentRecord();
  
  
/**
Algorithm changeAssignmentGradeForStudent(asnNum,grade)
Pre: asnNum :: Integer, the index of the assignment to grade
grade :: double, the amount to change the grade
Post: If the index is sensible, the appropriate grade is changed
(this method allows grades to be changed arbitrarily)
Return: true if the change was made, false otherwise
*/
public boolean changeAssignmentGradeForStudent (int asnNum, double grade);

/**
Algorithm changeExamGradeForStudent(grade)
Pre: grade :: double, the amount to change the grade
Post: the exam grade is changed
(this method allows grades to be changed arbitrarily)
Return: nothing
*/
public void changeExamGradeForStudent(double grade);
  
}

StudentADT.java

public class StudentADT implements Student {
  
private String firstName;
private String lastName;
private int stNum;
private double [] agrades;
private double egrade;

  
/**
Algorithm StudentADT(firstNm, lastNm, stNo, asn1Grade, asn2Grade, asn3Grade, examGrade)
Constructor to create a student object
Pre: firstNm, lastNm :: String
stNo :: integer
asn1Grade, asn2Grade, asn3Grade :: double
examGrade :: double
Post: allocates memory on the heap for a new Student object
Return: a new Student object, with all fields filled in
*/
  
public StudentADT(String firstNm, String lastNm, int stNo, double asn1Grade, double asn2Grade, double asn3Grade, double examGrade){   
this.firstName = firstNm;
this.lastName = lastNm;
this.stNum = stNo;
this.agrades = (double[]) new double[3];
this.agrades[0] = asn1Grade;
this.agrades[1] = asn2Grade;
this.agrades[2] = asn3Grade;
this.egrade = examGrade;
}

/**
Algorithm displayStudentRecord()
Pre:
Post: displays Student info
Return: nothing

*/
public void displayStudentRecord() {
System.out.println("Record for " + this.lastName + ", " + this.firstName + " (" + this.stNum + ") ");
System.out.println("Assignment grades");
for (int i = 0 ; i <= 2; i ++)
System.out.println(this.agrades[i]);
System.out.println("Exam grade: " + this.egrade);
}
  
/**
Algorithm changeAssignmentGradeForStudent(asnNum,grade)
Pre: asnNum :: Integer, the index of the assignment to grade
grade :: double, the amount to change the grade
Post: If the index is sensible, the appropriate grade is changed
(this method allows grades to be changed arbitrarily)
Return: true if the change was made, false otherwise
*/
public boolean changeAssignmentGradeForStudent (int asnNum, double grade) {
  
if (asnNum < 0 || asnNum > 2)
return false;
else {
this.agrades[asnNum] = this.agrades[asnNum] + grade;
return true;
}
}
  
  
/**
Algorithm changeExamGradeForStudent(grade)
Pre: grade :: double, the amount to change the grade
Post: the exam grade is changed
(this method allows grades to be changed arbitrarily)
Return: nothing
*/

public void changeExamGradeForStudent(double grade) {
this.egrade = this.egrade + grade;
}

  
}

In: Computer Science

Create a directory called CIS153 Create new files based on each line from mydata.txt. Each new...

  1. Create a directory called CIS153
  2. Create new files based on each line from mydata.txt. Each new file name starts with newFile. The files will be saved in CIS153 directory
  3. Delete all files that were created from step 2
  4. Delete the directory created from step 1
  5. Redirect the out from step 3 & 4 to a file called output.txt

In: Computer Science

Calculate the pH of each of the following solutions at 25oC. (a) 0.10 M NH3 pH...

Calculate the pH of each of the following solutions at 25oC.

(a) 0.10 M NH3

pH =

(b) 0.050 M C5H5N (pyridine) (Kb for pyridine is 1.7 × 10-9)

pH =

In: Chemistry

Fogerty Company makes two products—titanium Hubs and Sprockets. Data regarding the two products follow: Direct Labor-Hours...

Fogerty Company makes two products—titanium Hubs and Sprockets. Data regarding the two products follow:

Direct
Labor-Hours per Unit
Annual
Production
Hubs 0.50 18,000 units
Sprockets 0.10 46,000 units

Additional information about the company follows:

  1. Hubs require $30 in direct materials per unit, and Sprockets require $15.

  2. The direct labor wage rate is $14 per hour.

  3. Hubs require special equipment and are more complex to manufacture than Sprockets.

  4. The ABC system has the following activity cost pools:

Estimated Activity
Activity Cost Pool (Activity Measure) Overhead Cost Hubs Sprockets Total
Machine setups (number of setups) $ 23,085 95 76 171
Special processing (machine-hours) $ 147,000 4,900 0 4,900
General factory (organization-sustaining) $ 82,600 NA NA NA

Required:

1. Compute the activity rate for each activity cost pool.

2. Determine the unit product cost of each product according to the ABC system.

In: Accounting

1. Imagine that you want to obtain a loan from a bank for a business that...

1. Imagine that you want to obtain a loan from a bank for a business that you operate through a corporation. The bank wants assurances that the loan will be repaid. It gives you a choice to advance the loan to the corporation and for the bank to obtain from the corporation a mortgage registered against land owned by the corporation, or to advance the loan to the corporation but to ask you to give the bank a personal guarantee of the loan. What are the advantages or disadvantages under either scenario?

In: Finance

Write a function named int2ordinal that takes an integer as its only parameter and returns the...

Write a function named int2ordinal that takes an integer as its only parameter and returns the number with its appropriate suffix as its result (stored in a string). For example, if your function is passed the integer 1 then it should return the string "1st". If it is passed the integer 12 then it should return the string "12th". If it is passed 2003 then it should return the string "2003rd". Your function must not print anything on the screen.

You can use the remainder operator to extract the last digit of an integer by computing the remainder when the integer is divided by 10. Similarly, you can extract the last two digits of an integer by computing the remainder when the integer is divided by 100. For example 29 % 10 is 9 while 1911 % 100 is 11. Then you can construct the string that needs to be returned by your function by converting the integer parameter into a string by calling the str function, and concatenating the appropriate suffix using the + operator.

In: Computer Science