I\'m having trouble using linked lists. Please give brief explanation along with
ID: 3564059 • Letter: I
Question
I'm having trouble using linked lists. Please give brief explanation along with reply. I want to insert and delete a node into a linked list of more than one type. I tried to do insertion but it is wrong. The goal is to print out each grade chunk (Name, Possible Points, Points Earned, Grade Type) and calculate the final grade at the end. I was thinking of making different linked lists for each parameter but I don't think that's what is the objective.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#pragma warning(disable: 4996)
#define max 10
struct Entry { // a node to hold personal details
char name[255];
float points_possible;
float points_earned;
struct Entry *next;
};
struct Entry Gradebook[max]; // an array of structures
int tail = 0;
int insertion();
//int print_all();
int delete();
typedef enum {
Final = 0, Midterm, Quiz, Project, Homework
} GradeType;
int main() { // print a menu for selection
char command;
//print menu options
printf("Enter your selection ");
printf(" i: insert a new grade book entry ");
printf(" d: delete a grade book entry ");
printf(" p: print grades ");
printf(" q: quit Application ");
scanf("%c", &command);
do {
switch (command) {
case 'i':
insertion();
break;
/*
case 'd':
delete();
break;
*/
case 'q':
break;
default:
printf("Invalid input. Please enter an option listed above.");
}
} while (command != 'q');
return 0;
}
int insertion() { // insert a new entry at the end of Gradebook
struct Entry gradeEntry;
if (tail == max) {
printf("There are no more places to insert. ");
return -1;
}
else {
printf("Enter assignment name: ");
scanf("%s", Gradebook[tail].name);
printf("Enter the number of possible points: ");
scanf("%f", &Gradebook[tail].points_possible);
printf("Enter the numbers of points earned: ");
scanf("%f", Gradebook[tail].points_earned);
printf("Enter Grade Type (Final = 0, Midterm = 1, Project = 3, Homework = 4): ");
scanf("%i", GradeType[tail].points_earned);
tail++;
printf("The number of entries = %i ", tail);
return 0;
}
}
int delete() { }
Explanation / Answer
scanf("%f", Gradebook[tail].points_earned); this should be modified as scanf("%f",&Gradebook[tail].points_earned);
and you should use one more variable in struct int grade.
I think usually you would want the behaviour of %d instead of the behaviour of %i, because %i will interpret numbers with leading zeroes as octal and you probably do not want that; an end user would typically not understand why typing in "12" and "012" give different results!
scanf("%i", GradeType[tail].points_earned); is wrong instead of it you can use scanf("%id",Gradebook[tail].grades);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.