# Tutor profile: Tj A.

## Questions

### Subject: C++ Programming

Write a simple function that swaps the values of two variables. Use pass by reference notation.

Pass by reference is an ability of C++. Those coming from a C programming background may find it confusing at first. This notation allows the programmer to bypass pointer notation that many can find tedious if they do not have a background in C programming. The code for the function is as follows: void swap_num( int &i, int &j) { int temp = i; i = j; j = temp; } Those coming from a C programming background may be surprised to find that when this function is called instead of copies being made and modified the actual original variables have now been swapped. This is the power of passing in arguments by reference. It allows for code that's a bit more readable and easier to follow.

### Subject: C Programming

Without using any functions in the string.h standard library for c write a function that determines the length of a string. The length includes all letters except for any null-terminators.

Strings in C are Null terminated, meaning they end with the '\0' (Null Character). Because of this, we do not know the length of the string until we iterate through it. A simple function that could return the string length would be as follows: int string_length( char* string ) { if( string == NULL || string[0] == NULL ) return 0; int length; length = 0; while( string[length] != '\0' ) { length++; } return length; } Note: Some limitations include we can only return a length up to the maximum value of an integer. This can be remedied by using alternative types with longer variable sizes. Also note how we did error checking at the beginning to see if the input passed in was valid in the first place. If the variable string is NULL we can check for it and we don't have to worry about a segmentation fault in the second part of the if statement ( || string[0] == NULL ) because as soon as string == NULL is evaluated to true, the return 0 statement will be executed. Finally note that length was initialized to 0. Local variables need to be initialized through code because the compiler will not do it for you.

### Subject: Algebra

Find the point of intersection of these two lines. If there is no intersection state so. If the lines are coincident state so. y = 3x +7 y = -x - 10

We already have the equations of the lines in the form {y = mx+b} with m being the slope. We can quickly look at the values of the slopes of both equations and determine if we will have a single point of intersection. m1 = 3, and m2 = -1. Because these values are different we can trust that we will have one point of intersection. Furthermore we know the point of intersection will be a point on both lines, therefore we can solve for x or y in one equation and then substitute that into the other equation. Solution: y = 3x + 7 [Equation already solved for y] 3x+7 = -x - 10 [Plug in the value of y into the other equation] 4x = -17 [Add x to both sides. Subtract 7 from both sides] x = -17/4 [Divide by 4 on both sides] x = -4.25 y = 3*(-4.25) + 7 [Plug in the value of x we just found] y = -5.75 Point of intersection is (-4.25, -5.75)

## Contact tutor

needs and TJ will reply soon.