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

In C coding: Create 2 functions and 1 test case for each function in main() with

ID: 3826367 • Letter: I

Question

In C coding:
Create 2 functions and 1 test case for each function in main() with expected output listed in comments. Descriptions of the functions are below.  with the skeleton main and the linked list structure declaration. There is a single test case setup because it requires at least one test case. You should ignore that test case and produce your own test case and expected output for each function.

create appropriate test case and expected output
function1() - Linked List  - Given a reference to a linked list:(1) print out the number of nodes in the list, (2) print out the positive values from the list, and(3) calculate, print out, and return the sum of the negative 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 (do not use strlen() for this portion of the code),(2) print out the lower case characters from the c-string, and(3) calculate, print out, and return the average number of words that contain the same letter as R R R R.

Start your program with:
#include <stdio.h>
#include <stdlib.h>

struct SSL1 {
int value;
struct SSL1 *next;
};

function1()

function2()


int main() {

return 0;
}


Explanation / Answer

#include <stdio.h>
#include <stdlib.h>

struct SSL1 {
   int value;
   struct SSL1 *next;
};

int function1(struct SSL1 *start){
    struct SSL1 *p;
    int count;
    int sum;
    p = start;
    count = 0;
    while (p != NULL){
        count++;
        if (p->value > 0){
           cout << p->value << endl;
        }
        if (p->value < 0){
           sum = sum + p->value;
        }
    }
    cout << "No of nodes:" << cout;
    cout << "Sum of negative entries: << sum << endl;
    return sum;
}

int function2(char *start){
    char *p;
    p = start;
    int count, lowercasecount;
    count = 0;
    lowercasecount = 0;
    while (*p != ''){
        if (*p >= 'a' && *p <= 'z'){
           lowercasecount++;
        }
        count++;
        p++;
    }
    cout << "Length of string:" << count;
    cout << "Lowercase count:" << lowercasecount;
    return 0;
}

int main() {
   int i, sum;
   struct SSL1 *start, *p;
   char str[50];

   start = NULL;
  
   for (i = 0; i<10; i++){
       if (start != NULL){
           start = (struct SSL1 *)malloc(sizeof(struct SSL1));
           scanf("%d", &start->value);
           start->next = NULL;
        }
        else {
            p = start;
            while (p->next ! = NULL){
                  p = p->next;
            }
            p->next = (struct SSL1 *)malloc(sizeof(struct SSL1));
            p = p->next;
            scanf("%d", &p->value);
            p->next = NULL;
        }
   }
   sum = function1(start);
   cout << "Enter a string:";   /* Let the length of the string < 50 */
   sum = function2(str);    
   return 0;
}

/* The 3rd requirement of function2 is not very clear so not implemented */