write the program in c++ the answers i have been given dont work Classes and Obj
ID: 658674 • Letter: W
Question
write the program in c++
the answers i have been given dont work
Classes and Objects: Write a class called Student that has the following member variables: name - string that holds the student's name idNumber - Integer that holds the student's ID number department - string that holds the student's school / major gpa - A flout that holds the student's overall GPA The class should have the following constructors: A Constructor that accepts the student's name as an argument and assigns it to proper variable A constructor that accepts the student's name. ID number, department, and gpa and assigns them to the proper variables A default constructor that assigns empty strings (""") to the name and department, and 0 to the ID number and GPA Write mutator functions that con store numbers in the appropriate variables and accessory functions that can return the values in these member variables Once you have written the class, write a mam program that creates two objects with the following data and display them on the screen:Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
typedef struct DLNode Node;
typedef struct DLNode
{
int ID;
char *Fname;
char *Lname;
char *Dept;
float GPA;
Node * prev;
Node * next;
} Node;
typedef struct DLList
{
int count;
Node * first;
Node * last;
} List;
void DLList_init(List * list)
{
list->first = NULL;
list->last = NULL;
list->count = 0;
}
void DLList_add_node(List * list, int ID, char *Fname, char *Lname, char *Dept, float GPA)
{
Node * newNode;
newNode = malloc(sizeof(Node));
if(!newNode)
{
printf("Malloc failed, new node not created.");
exit(EXIT_FAILURE);
}
newNode->ID = ID;
newNode->Fname = Fname;
newNode->Lname = Lname;
newNode->Dept = Dept;
newNode->GPA = GPA;
if(list->last)
{
list->last->next = newNode;
newNode->prev = list->last;
list->last = newNode;
} else {
list->first = newNode;
list->last = newNode;
}
list->count++;
}
void DLList_print(List * sortedlist, FILE *fout)
{
Node * node;
for(node = sortedlist->first; node != NULL; node = node->next)
{
fprintf(fout, "%d,%s,%s,%s,%f ", node->ID, node->Fname, node->Lname, node->Dept, node->GPA);
free(node->Dept);
free(node->Lname);
free(node->Fname);
free(node);
}
}
void Insertion_sort(List * list, List * sortedlist, FILE *fout)
{
Node * indexNode;
Node * nextNode;
Node * firstNode;
indexNode = list->first;
nextNode = indexNode->next;
for(indexNode = list->first; indexNode->next != NULL; indexNode = indexNode->next)
{
nextNode = indexNode->next;
if(indexNode->ID < nextNode->ID)
{
if(sortedlist->first == NULL)
{
firstNode = indexNode;
sortedlist->first = firstNode;
sortedlist->last = firstNode;
} else {
firstNode->next = indexNode;
indexNode->prev = firstNode;
sortedlist->last = indexNode;
}
} else {
nextNode->prev = indexNode;
indexNode->next = nextNode;
sortedlist->last = nextNode;
}
}
DLList_print(sortedlist, fout);
}
int main(int argc, char *argv[])
{
FILE *fin, *fout;
int ID;
char *Fname;
char *Lname;
char *Dept;
float GPA;
char *fin_path;
char *fout_path;
List sortedlist;
DLList_init(& sortedlist);
List list;
DLList_init(& list);
if(argv[1] && argv[2])
{
fin_path = argv[1];
fout_path = argv[2];
} else {
printf("Input and output file names were not supplied! ");
return 1;
}
fin = fopen(fin_path, "r");
if(fin == NULL)
{
printf("Can't open input file! ");
return 1;
}
while (fscanf(fin, "%d %ms %ms %ms %f", &ID, &Fname, &Lname, &Dept, &GPA) == 5)
{
DLList_add_node(& list, ID, Fname, Lname, Dept, GPA);
}
fout = fopen(fout_path, "w");
if(fout == NULL)
{
printf("Can't open output file!");
return 1;
}
Insertion_sort(& list, & sortedlist, fout);
fclose(fin);
fclose(fout);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.