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

Use the following code as a template to create your personalize grade book. #inc

ID: 3563283 • Letter: U

Question

Use the following code as a template to create your personalize grade book.  

#include <stdio.h>  

#include <string.h>

#include <ctype.h>

#pragma warning(disable: 4996)

#define max 100

struct contact {                                // a node to hold personal details

       char name[30];

       int phone;

       char email[30];

};

struct contact contactbook[max];              // an array of structures, 100 entries

int tail = 0;                                  // global variable

void flush();                                  // forward declaration of functions

void branching(char c);                        

int insertion();

int print_all();

int search_contact();

int delete_contact();

int main() { // print a menu for selection

       char ch = 'i';

       ungetc(' ', stdin); // inject input buffer with a return character

       do {

              printf("Enter your selection ");

              printf(" i: insert a new entry ");

              printf(" d: delete an entry ");

              printf(" s: search an entry ");

              printf(" p: print all entries ");

              printf(" q: quit ");

             

              flush();                                 // flush input buffer

              ch = tolower(getchar());                

              branching(ch);

       } while (ch != 113);

       return 0;

}

void flush() {

       int c;

       do {

              c = getchar();

       } while (c != ' ' && c != EOF);

}

void branching(char c) {    // branch to different tasks

       switch (c) {

       case 'i':

              insertion();

              break;

       case 's':

              search_contact();

              break;

       case 'd':

              delete_contact();

              break;

       case 'p':

              print_all();

              break;

       case 'q':

              break;

       default:

              printf("Invalid input ");

       }

}

int insertion() {    // insert a new entry at the end

       if (tail == max) {

              printf("There are no more places to insert. ");

              return -1;

       }

       else {

              printf("Enter name, phone, email: ");

              scanf("%s", contactbook[tail].name);

              // &contactbook[tail].name is an array. No "&" is needed

              scanf("%d", &contactbook[tail].phone, sizeof(contactbook[tail].phone));

              scanf("%s", contactbook[tail].email);

              tail++;

              printf("The number of entries = %d ", tail);

              return 0;

       }

}

int print_all() {   

// print name, phone, and email for each contact in the contactbook

       int i;

       if (tail == 0) {

              printf("No entries found.");

       }

       else {

              for (i = 0; i < tail; i++) {

                     printf(" name = %s ", contactbook[i].name);

                     printf("phone = %d ", contactbook[i].phone);

                     printf("email = %s ", contactbook[i].email);

              }

       }

       return 0;

}

int search_contact() {      // print phone and email via name

       char sname[30]; int i;

      

       printf("Please enter the name to be searched for: ");

       scanf("%s", sname); //sname is an array, no & needed

      

       for (i = 0; i<tail; i++)

              if (strcmp(sname, contactbook[i].name) == 0) {

                     printf("phone = %d ", contactbook[i].phone);

                     printf("email = %s ", contactbook[i].email);

                     return i;

              }

       printf("The name does not exist. ");

       return -1;

}

int delete_contact() {

       int i, k;

       k = search_contact();

       if (k == -1) {

              printf("The name does not exist. "); return -1;

       }

       else {

              for (i = k; i<tail; i++) {

                     strcpy(contactbook[i].name, contactbook[i + 1].name);

                     contactbook[i].phone = contactbook[i + 1].phone;

                     strcpy(contactbook[i].email, contactbook[i + 1].email);

                     printf("The index deleted is: %d ", k);

              }

              tail--;

              return k;

       }

}

In this problem, you will also define a GradeType enumeration which will include a predefine set of categories, e.g. Final, Midterm, Quiz, Project, and Homework.                                                                                                      

            Users will select from the following options: I, D, P, or Q, which correspond to insert, delete, print, or quit respectively. (Hitting Q will exit the application.)                                                                                             [5]

             Use the following formula as a guide:

             Final Grade = 0.22 * (Final Exam PE / Final Exam PP) + 0.18 * (Midterm PE / Midterm PP) + 0.10 * (Quizzes PE / Quizzes PP) + 0.20 * (Project PE / Project PP) + 0.30 * (Homework PE / Homework PP);

Explanation / Answer

// Member-function definitions for class GradeBook that // uses a switch statement to count A, B, C, D and F grades. #include using std::cout; using std::cin; using std::endl; #include "GradeBook.h" // include definition of class GradeBook // constructor initializes courseName with string supplied as argument; // initializes counter data members to 0 GradeBook::GradeBook( string name ) { setCourseName( name ); // validate and store courseName aCount = 0; // initialize count of A grades to 0 bCount = 0; // initialize count of B grades to 0 cCount = 0; // initialize count of C grades to 0 dCount = 0; // initialize count of D grades to 0 fCount = 0; // initialize count of F grades to 0 } // end GradeBook constructor // function to set the course name; limits name to 25 or fewer characters void GradeBook::setCourseName( string name ) { if ( name.length()
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