Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Creating a structure of student information, allocating in memory, then printing to the screen. We just learned structures so this is just for practice. I'm

Creating a structure of student information, allocating in memory, then printing to the screen. We just learned structures so this is just for practice. I'm confused why it's not working because it's basically the same as an example he gave us except I made my own using student data. This is the error:

image text in transcribedThis is what I have:

types.h

enum SUBJECT { MATH, WRITING, COMPUTER_SCIENCE, ENGINEERING, SCIENCE };

struct Student { char* name; float grade; int credits; SUBJECT subject; };

void free_student(Student* student); void print_student(const Student* student); Student* create_student(float* grade, int credits, const char* name);

students.cpp

#include #include "types.h"

const char* SUBJECTS[] = { "Math", "Writing", "Computer Science", "Engineering", "Science" };

Student* create_student(float* grade, int credits, const char* name) { const int len = strlen(name) + 1; // setting dynamic length for name char* student_name1 = new char[len]; // allocating space in memory for student_name strcpy_s(student_name1, len, name); // name gets copied into student_name with enough space return new Student{ student_name1, 86.67, 4, MATH }; }

void print_student(const Student* student) { cout name grade credits subject]

void free_student(Student* student) { delete[] student->name; delete student; }

main.cpp

/* * This program creates a structure of student data, reads into dynamic memory, then prints to the screen * Output should have: Heading, name, course, subject, and grade. */

#include #include #include "students.cpp" #include "types.h"

using std::cin; using std::cout; using std::endl; using std::left; using std::right; using std::setw;

int main() { char student_name1[] = "Jake"; Student jake{ student_name1, 86.7, 4, MATH };

print_student(&jake); cout

The errors are happening on MATH, not sure why since I thought that's how you set it up. Thank you!

and E0144 C2084 a value of type "SUBJECT" cannot be used to initialize an entity of type "SUBJECT", function 'Student *create_student(float *,int,const char *)' already has a body Grade Calculator Grade Calculator students.cpp students.cpp 11. 5 and E0144 C2084 a value of type "SUBJECT" cannot be used to initialize an entity of type "SUBJECT", function 'Student *create_student(float *,int,const char *)' already has a body Grade Calculator Grade Calculator students.cpp students.cpp 11. 5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions

Question

=+applying to all or most employers and employees?

Answered: 1 week ago