Question

In: Computer Science

Instructions: You are givne main.c and exam.h. Your task is to implement exam.c. write the code...

Instructions:
You are givne main.c and exam.h.
Your task is to implement exam.c.
write the code for these 20 functions on repl.it.
*/

#include 
#include "exam/exam.h"

int main(void) {
  return 0;
}
/*
/*
exam.h
*/

#ifndef _EXAM_H_
#define _EXAM_H_

// 1
// Display title of code and your name. ( koorsh maghsoodi my name)
// See exam.txt for sample output.
void exam_hello_world(void);

// 2
// Display argc and all argv[] values.
// See exam.txt for sample output.
// returns: number of arguments
int exam_cmd_line_args(int argc, char *argv[]);

// 3
// Display info about signed integer data types.
// See exam.txt for sample output.
// Return number of signeed integer data types
int exam_signed_integer_data_types(void);

// 4
// Display info about unsigned integer data types.
// See exam.txt for sample output.
// Return number of unsigned integer data types
int exam_unsigned_integer_data_types(void);

// 5
// Display info about these data types:
// int8_t, uint8_t
// int16_t, uint16_t
// int32_t, uint32_t
// See exam.txt for sample output.
// Return number of unsigned integer data types
int exam_stdint_integer_data_types(void);

// 6
// Display info about floating-point data types.
// See exam.txt for sample output.
int exam_floating_data_types(void);

// 7
// Return the sum of three integer numbers.
// See exam.txt for sample output
int exam_sum(int n1, int n2, int n3);

// 8
// Given two integer numbers, return:
// -1 if n1 is less than n2
// 0 if n1 is equal to n2
// 1 if n1 is greater than n2
// See exam.txt for sample output
int exam_compare(int n1, int n2);

// 9
// Given two integer numbers,
// return the sum of n1 to n2.
// For example, if n1=2 and n2=4,
// return sum of 2+3+4, i.e. 9
// Do this using a for loop.
int exam_for(int n1, int n2);

// 10
// Given two integer numbers,
// return the sum of n1 to n2.
// For example, if n1=2 and n2=4,
// return sum of 2+3+4, i.e. 9
// Do this using a while loop.
int exam_while(int n1, int n2);

// 11
// Given two integer numbers,
// return the sum of n1 to n2.
// For example, if n1=2 and n2=4,
// return sum of 2+3+4, i.e. 9
// Do this using a do_while loop.
int exam_do_while(int n1, int n2);

// 12
// Display info about enum data types.
// See exam.txt for sample output.
typedef enum {
  EXAM_ERROR_OK = 0,
  EXAM_ERROR_BAD_PARAM,
  EXAM_ERROR_OUT_OF_RANGE,
  EXAM_ERROR_IO
} exam_error_t;
exam_error_t exam_typedef_enum_data_types(void);

// 13
// Add a student.
// If the max students is reached return
// EXAM_ERROR_OUT_OF_RAMGE,
// else return EXAM_ERROR_OK
// See exam.txt for sample output
#define EXAM_MAX_STUDENTS 3
typedef struct {
  int id;
  float average;
  char *name;
} student_t;
exam_error_t exam_add_student(student_t *s);

// 14
// List all students
// See exam.txt for sample output
// Return the number of students listed
int exam_list_students(void);

// 15
// Remove a student by id 
// See exam.txt for sample output
// Return EXAM_ERROR_OK if studentt was
// removed. Else return EXAM_ERROR_BAD_PARAM
exam_error_t exam_remove_student_by_id(int id);

// 16
// Remove a student by name
// See exam.txt for sample output
// Return EXAM_ERROR_OK if studentt was
// removed. Else return EXAM_ERROR_BAD_PARAM
exam_error_t exam_remove_student_by_name(char *name);

//17
// Write the list of students to a file.
// Return EXAM_ERROR_OK on success or
// Return EXAM_ERROR_BAD_PARAM if filenmae is NULL.
// Return EXAM_ERROR_IO if file write error
exam_error_t exam_write_students_to_file(char *filename);

//18
// Read the list of students from a file.
// Return EXAM_ERROR_OK on success or
// Return EXAM_ERROR_BAD_PARAM if filenmae is NULL.
// Return EXAM_ERROR_IO if file write error
exam_error_t exam_read_students_from_file(char *filename);

//19
// Given an array of students (e.g. just read in from a file)
// display them to the console.
// Return the number of students displayed.
int exam_display_students_from_list(student_t s[], size_t size);

//20
// For each of the following files, read them in,
// and then display the following info:
// Filename, Number of Lines, Number of Characters
// main.c....
// exam/exam.h....
// exam/exam.c...
// Return the total number of LINES of all files,
// i.e. lines of main.c + exam.h + exam.c
int exam_return_total_lines(void);

#endif

YOUR SAMPLE OUTPUT SHOULD LOOK LIKE THIS:

1 - exam_hello_world
        CSCI 112 Final
        Code by Norman McEntire
2 - exam_cmd_line_args
        argc: 4
        argv[0]: main
        argv[1]: one
        argv[2]: two
        argv[3]: three
value returned: 4
3 - exam_signed_integer_data_types
        type    size
        ----    ----
        char    1
        short   2
        int     4
        long    8
value returned: 4
4 - exam_unsigned_integer_data_types
        type    size
        ----    ----
        unsigned char   1
        unsigned short  2
        unsigned int    4
        unsigned long   8
value returned: 2
5 - exam_stdint_integer_data_types
        type            size
        ----            ----
        uint8_t         1
        uint16_t        2
        uint32_t        4
value returned: 3
6 - exam_floating_data_types
        type    size
        ----    ----
        float   4
        double  8
value returned: 2
7 - exam_sum
        n1: 10, n2: 20, n3: 30
value returned: 60
8 - exam_compare
        n1: -10, n2: 20
value returned: -1
8 - exam_compare
        n1: 10, n2: 10
value returned: 0
8 - exam_compare
        n1: 20, n2: 10
value returned: 1
9 - exam_for
        n1: 10, n2: 20
value returned: 165
10 - exam_while
        n1: 10, n2: 20
value returned: 165
11 - exam_do_while
        n1: 10, n2: 20
value returned: 165
12 - exam_typedef_enum_data_types
        EXAM_ERROR_OK: 0
        EXAM_ERROR_BAD_PARAM: 1
        EXAM_ERROR_OUT_OF_RANGE: 2
        EXAM_ERROR_IO: 3
13 - exam_add_student
        id: 123, average: 94.50, name: John
        Currrent num_students: 0
        Student added. updated num_students: 1
value returned: 0
13 - exam_add_student
        id: 234, average: 95.60, name: Sally
        Currrent num_students: 1
        Student added. updated num_students: 2
value returned: 0
13 - exam_add_student
        id: 345, average: 96.70, name: Billy
        Currrent num_students: 2
        Student added. updated num_students: 3
value returned: 0
13 - exam_add_student
        id: 456, average: 97.80, name: Paul
        Currrent num_students: 3
        Max number of students reachd!
value returned: 2
14 - exam_list_students
        Total of 3 students:
        id: 123, average: 94.50, name: John
        id: 234, average: 95.60, name: Sally
        id: 345, average: 96.70, name: Billy
value returned: 3
15 - exam_remove_student_by_id
        id: 234
        FOUND! Student removed!
value returned: 0
14 - exam_list_students
        Total of 2 students:
        id: 123, average: 94.50, name: John
        id: 345, average: 96.70, name: Billy
value returned: 2
15 - exam_remove_student_by_id
        id: 999
        NO STUDENT FOUND!
value returned: 1
14 - exam_list_students
        Total of 2 students:
        id: 123, average: 94.50, name: John
        id: 345, average: 96.70, name: Billy
value returned: 2
16 - exam_remove_student_by_name
        name: Billy Bob
        NO STUDENT FOUND!
value returned: 1
14 - exam_list_students
        Total of 2 students:
        id: 123, average: 94.50, name: John
        id: 345, average: 96.70, name: Billy
value returned: 2
16 - exam_remove_student_by_name
        name: No One
        NO STUDENT FOUND!
value returned: 1
14 - exam_list_students
        Total of 2 students:
        id: 123, average: 94.50, name: John
        id: 345, average: 96.70, name: Billy
value returned: 2
13 - exam_add_student
        id: 234, average: 95.60, name: Sally
        Currrent num_students: 2
        Student added. updated num_students: 3
value returned: 0
13 - exam_add_student
        id: 456, average: 97.80, name: Paul
        Currrent num_students: 3
        Max number of students reachd!
value returned: 2
14 - exam_list_students
        Total of 3 students:
        id: 123, average: 94.50, name: John
        id: 234, average: 95.60, name: Sally
        id: 345, average: 96.70, name: Billy
value returned: 3
17 - exam_write_students_to_file
        filename: (null)
Error: filename is NULL
value returned: 1
17 - exam_write_students_to_file
        filename: asdf.txt
value returned: 0
18 - exam_read_students_from_file
        filename: asdf.txt
        123 94.500000 John
        234 95.599998 Sally
        345 96.699997 Billy
value returned: 0
19 - exam_display_students_from_list
id: 11, average: 90.11, name: Sam
id: 22, average: 90.22, name: Jack
id: 33, average: 90.33, name: Lisa
value returned: 0
20 - exam_return_total_lines
        main.c:         lines: 253, chars: 6881
        exam/exam.h:    lines: 158, chars: 4059
        exam/exam.c:    lines: 398, chars: 10282
Total lines: 809

Solutions

Expert Solution

#include <stdio.h>

#include<stdint.h>

void exam_hello_world(void){

printf("1 - exam_hello_world\n");

printf("CSCI 112 Final\n");

printf("Code by Norman McEntire\n");

}

int exam_cmd_line_args(int argc, char *argv[]){

int i;

printf("\n2 - exam_cmd_line_args");

printf("argc:%d",argc);

// for(i=0;i<argc;i++){

// printf("argv[%d]:%c",i,argv[i]);

// }

return argc;

}

int exam_signed_integer_data_types(void){

char c;

int i;

short s;

long l;

printf("3 - exam_signed_integer_data_types\n");

printf("type size\n");

printf("---- ----\n");

printf("char %ld \n",sizeof(c));

printf("short %ld \n",sizeof(s));

printf("int %ld \n",sizeof(i));

printf("long %ld \n",sizeof(l));

return 4;

}

int exam_unsigned_integer_data_types(void){

unsigned char c;

unsigned int i;

unsigned short s;

unsigned long l;

printf("\n4 - exam_unsigned_integer_data_types");

printf("\ntype size\n");

printf("---- ----\n");

printf("unsigned char %ld \n",sizeof(c));

printf("unsigned short %ld \n",sizeof(s));

printf("unsigned int %ld \n",sizeof(i));

printf("unsigned long %ld \n",sizeof(l));

return 2;

}

int exam_stdint_integer_data_types(void){

int8_t i8;

int16_t i16;

int32_t i32;

printf("\n5 - exam_stdint_integer_data_types");

printf("\ntype size\n");

printf("---- ----\n");

printf("uint8_t %ld \n",sizeof(i8));

printf("uint16_t %ld \n",sizeof(i16));

printf("uint32_t %ld \n",sizeof(i32));

return 3;

}

int exam_floating_data_types(void){

float f;

double d;

printf("\n6 - exam_floating_data_types");

printf("\ntype size");

printf("\n---- ----");

printf("\nfloat %ld \n",sizeof(f));

printf("double %ld \n",sizeof(d));

// float 4

// double 8

return 2;

}

int exam_sum(int n1, int n2, int n3){

printf("\n7 - exam_sum");

printf("\nn1: %d n2: %d n3: %d",n1,n2,n3);

return n1+n2+n3;

}

int exam_compare(int n1, int n2){

printf("8 - exam_compare");

printf("\nn1: %d n2: %d",n1,n2);

if(n1<n2)

return -1;

else if(n1==n2)

return 0;

else

return 1;

}

int exam_for(int n1, int n2){

int i,sum=0;

printf("\n9 - exam_for");

printf("\nn1: %d n2: %d",n1,n2);

for(i=n1;i<=n2;i++)

sum+=i;

return sum;

}

int exam_while(int n1, int n2){

int sum=0;

printf("\n10 - exam_while");

printf("\nn1: %d n2: %d",n1,n2);

while(n1<=n2){

sum+=n1;

++n1;

}

return sum;

}

int exam_do_while(int n1, int n2){

int sum=0;

printf("\n11 - exam_do_while");

printf("\nn1: %d n2: %d",n1,n2);

do{

sum+=n1;

++n1;

}

while(n1<=n2);

return sum;

}

int main(void) {

int fun3,fun4,fun5,fun6,fun7,fun8,fun9,fun10,fun11;

exam_hello_world();

fun3=exam_signed_integer_data_types();

printf("value returned:%d",fun3);

fun4=exam_unsigned_integer_data_types();

printf("value returned:%d",fun4);

fun5=exam_stdint_integer_data_types();

printf("value returned:%d",fun5);

fun6 = exam_floating_data_types();

printf("value returned:%d",fun6);

fun7 = exam_sum(10,20,30);

printf("\nvalue returned:%d\n",fun7);

fun8 = exam_compare(-10,20);

printf("\nvalue returned:%d\n",fun8);

fun8 = exam_compare(10,10);

printf("\nvalue returned:%d\n",fun8);

fun8 = exam_compare(20,10);

printf("\nvalue returned:%d\n",fun8);

fun9 = exam_for(10,20);

printf("\nvalue returned:%d\n",fun9);

fun10 = exam_while(10,20);

printf("\nvalue returned:%d\n",fun10);

fun11 = exam_do_while(10,20);

printf("\nvalue returned:%d\n",fun11);

return 0;

}


Related Solutions

Code in C Instructions For this programming assignment you are going to implement a simulation of...
Code in C Instructions For this programming assignment you are going to implement a simulation of Dijkstra’s solution to the Dining Philosophers problem using threads, locks, and condition variables. Dijkstra’s Solution Edsgar Dijkstra’s original solution to the Dining Philosophers problem used semaphores, but it can be adapted to use similar mechanisms: • Each philosopher is in one of three states: THINKING, HUNGRY, or EATING. • Every philosopher starts out in the THINKING state. • When a philosopher is ready to...
Write the code to implement the concept of inheritance forVehicles. You are required to implement inheritance...
Write the code to implement the concept of inheritance forVehicles. You are required to implement inheritance betweenclasses. You have to write four classes in C++ i.e. one superclass, two sub classes and one driver class. Vehicle is the super class whereas Bus and Truck are sub classesof Vehicle class. Transport is a driver class which contains mainmethod. Detailed description of Vehicle (Super class): The class Vehicle must have following attributes: 1. Vehicle model 2. Registration number 3. Vehicle speed (km/hour)...
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
For this problem, you will be asked to write some code to accomplish a particular task...
For this problem, you will be asked to write some code to accomplish a particular task given the code fragment below. Each task may depend on the tasks that came before it. Your code must be syntactically correct. None of your operations for this problem may affect S::m_unique. class S { public: S(int init, int size, int id) :m_num(init), m_size(size) {                m_unique = new int[m_num]; for (int i = 0; i < m_num; i++)       m_unique[i] = id;...
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a...
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a sinusoid wave having two components as f1 = 3kHz and f2 = 5kHz and then sample it with fs = 10kHz. Calculate its fft with zero frequency component in the middle. Plot it on a properly scaled w-axis. Specify if there is aliasing or not? If there is aliasing specify which component is casing the aliasing
n the instructions for this Task C, we're going to assume that you have completed your...
n the instructions for this Task C, we're going to assume that you have completed your script for Task B above; i.e. that you have a working dictionary-based version of the functions (originally named addToRecord(), etc. in Task A) now named addToHistogram(), etc. Let's assume that your dictionary-based function (from Task B above) that creates a histogram is named makeHistogram(). You are going to use your makeHistogram() in the following sub-tasks. In fact, you're welcome to include any function you...
Write VHDL code (behavior model) to implement a 4-bit modulo-9 counter and simulate your VHDL code...
Write VHDL code (behavior model) to implement a 4-bit modulo-9 counter and simulate your VHDL code of 4-bit modulo-9 counter in ModelSim, and capture the screenshot of your simulated waveform. Assume clock period Tclk=100ns, initially, the counter is reset to Q3Q2Q1Q0=0000 you need to simulate a complete counting cycle plus one more additional clock period after it is reset to “0000” state.
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine...
JAVA write a code for Task 1 and Task 2 and pass the test cases. Imagine you have a rotary combination lock with many dials. Each dial has the digits 0 - 9. At any point in time, one digit from each dial is visible. Each dial can be rotated up or down. For some dial, if a 4 is currently visible then rotating the dial up would make 5 visible; rotating the dial down would make 3 visible. When...
Write a Verilog code to implement 16 bit LFSR
Write a Verilog code to implement 16 bit LFSR
Write the code in C++. Write a program to implement Employee Directory. The main purpose of...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of the class is to get the data, store it into a file, perform some operations and display data. For the purpose mentioned above, you should write a template class Directory for storing the data empID(template), empFirstName(string), empLastName(string), empContactNumber(string) and empAddress(string) of each Employee in a file EmployeeDirectory.txt. 1. Write a function Add to write the above mentioned contact details of the employee into EmployeeDirectory.txt....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT