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

The assignment must be printed and stapled. Include name, course number, and ass

ID: 2082656 • Letter: T

Question

The assignment must be printed and stapled. Include name, course number, and assignment number at the top. Include the source code and a screen shot of the execution results for each program. Make sure to include header and line comments in the programs. The assignment must be neat and clear. Write a program using structures and pointers to implement the finite state machine described in the table below. The program should repeatedly display the current state ID number, current output value, then ask for a new input value. Follow a similar procedure to the lab 12 assignment. Start at state ID 0. Example output (highlighted text indicates example input): Current state ID: 0 Current output z: 4 Enter input value: 2 Current state ID: 2 Current output z: 15 Enter input value: Write a program that will ask the user to enter their name. The program should then create a string with the text: "Hello , have a great day!", replacing with the entered name. (Also make sure to keep the spaces). The program should then print the string. Use functions from the library.

Explanation / Answer

#include <stdio.h>

#include <string.h>

struct student

{

    int id;

    char name[30];

    float percentage;

};

int main()

{

    int i;

    struct student record1 = {1, "Raju", 90.5};

    struct student record2, *record3, *ptr1, record4;

    printf("Records of STUDENT1 - record1 structure ");

    printf("  Id : %d   Name : %s   Percentage : %f ",

            record1.id, record1.name, record1.percentage);

    // 1st method to copy whole structure to another structure

    record2=record1;    

    printf(" Records of STUDENT1 - Direct copy from "

           "record1 ");

    printf("  Id : %d   Name : %s   Percentage : %f ",

            record2.id, record2.name, record2.percentage);

    // 2nd method to copy using memcpy function

    ptr1 = &record1;

    memcpy(record3, ptr1, sizeof(record1));

    printf(" Records of STUDENT1 - copied from record1 "

           "using memcpy ");

    printf("  Id : %d   Name : %s   Percentage : %f ",

           record3->id, record3->name, record3->percentage);

    // 3rd method to copy by individual members

    printf(" Records of STUDENT1 - Copied individual "

           "members from record1 ");

    record4.id=record1.id;

    strcpy(record4.name, record1.name);

    record4.percentage = record1.percentage;

    printf("  Id : %d   Name : %s   Percentage : %f ",

            record4.id, record4.name, record4.percentage);

     return 0;

}

A version using Scanner for input:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote