Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN C LANGUAGE Create 2 functions and 1 test case for each function in main() wit

ID: 3826480 • Letter: I

Question

IN C LANGUAGE

Create 2 functions and 1 test case for each function in main() with expected output listed in comments.

-appropriate header in comments with name, lab section, date, ide used, etc.

-appropriate test case and expected output (5 points for each test case and 5 points for each expected output, 2 total test cases (5 + 5) * 2 =

function1() - Linked List - Given a reference to a linked list:

(1) print out the number of nodes in the list,

(2) print out the odd values from the list, and

(3) calculate, print out, and return the sum of the pos values from the list.

-function2() - pointers - Given a pointer to the first character that is the start of a c-string (remember c-strings end with a ''):

(1) determine and print out the length of the c-string without using strlen (using strlen() will result in a 0 for this portion of the code),

(2) print out the upper case characters from the c-string, and

(3) calculate, print out, and return the average number of words that contain the same letter as the last letter of YOUR first name.

Explanation / Answer

//Consider the we have a list of struct node structure

int function1(struct node *head)

{

int no_of_nodes=0;

int pos_sum=0;

struct node *temp=head;

while(temp!=NULL)

{

no_of_nodes++;

pos_sum+=temp->pos;

temp=temp->next;

}

cout<<"The number of nodes are : "<<no_of_nodes;

cout<<" The sum of pos values from the list is : "<<pos_sum;

temp=head;

cout<<" Odd values from list are : ";

while(temp!=NULL)

{

if(temp->pos%2!=0)

cout<<" "<<temp->pos;

temp=temp->next;

}

}

//Function 2

int function2(char *p)

{

int length=0;

char *temp=p;

while(temp!='')

{

length++;

temp++;

}

cout<<"Length of c string is : "<<length;

temp=p;

cout<<"Upper case letters from given c string are :";

while(temp!='')

{

if(*temp>=65 && *temp<92)

cout<<*temp<<" ";

temp++;

}

}