Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4249066
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:20:48+00:00 2026-05-21T04:20:48+00:00

We were given an assignment in our C programming class to modify a program

  • 0

We were given an assignment in our C programming class to modify a program to make it more object oriented. Part of this was to fix the toString method. The directions were:

 Modify the Student module to make it more object-oriented.

* Each Student object should have a function pointer that points to an 
  appropriate function for producing a string representation of the object.
* Provide a default toString method to each object when it is created. 
  The studentToString method should no longer be part of the Student interface 
  (as defined in Student.h)

However, we aren’t really sure what this means and would like to know if we are on the right track with what we are suppose to do. Here is the code from the Student.c file:

 #include <stdio.h>
 #include <stdlib.h>
 #include "Student.h"
 #include "String.h"

 static void error(char *s) {
     fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, s);
     exit(1);
 }

 extern Student newStudent(char *name, int age, char *major) {
     Student s;
     if (!(s = (Student) malloc(sizeof(*s))))
         error("out of memory");
     s->name = name;
     s->age = age;
     s->major = major;
     return s;
 }

 extern char *studentToString(Student s) {
     const int size = 3;
     char age[size + 1];
     snprintf(age, size, "%d", s->age);

     char *line = newString();
     line = catString(line, "<");
     line = catString(line, s->name);
     line = catString(line, " ");
     line = catString(line, age);
     line = catString(line, " ");
     line = catString(line, s->major);
     line = catString(line, ">");
     return line;
 }

We known that the *studentToString method will be replaced by a *toString method and we think that the *toString method will have the same contents as the *studentToString method. But we don’t understand how that makes it more object-oriented.
We have also determined, from the directions, that when we create a new Student object, we should have a pointer in the newStudent method that points to the new toString method.

We’re not looking for anyone to do the program for us. We just want to understand what we are suppose to do as our professor has been out of town for the week. Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:20:49+00:00Added an answer on May 21, 2026 at 4:20 am

    It sounds like he’s asking you to take the Student structure and add a pointer to a function inside the structure itself so that when you have a valid pointer to a Student structure you can do something like

    `myStudent->toString();`
    

    and have it return the same value as

    `studentToString(myStudent)`
    

    would have before. This makes it more object oriented because of the fact that you’re calling a toString method on an effective “instance” (for lack of better terms) of a Student structure and returning parameters related to that “instance.” Just as you would in some sort of object-based programming language.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a homework assignment I was given a Card class that has enumerated types
Full disclosure, this is part of a homework assignment (though a small snippet, the
I've been given the assignment to port some library routines to C# so our
Given a Python object of any kind, is there an easy way to get
Given a (source) patch file, what's the easiest way to apply this patch on
I'm a programming student in my first C++ class, and recently we were encouraged
NOTE: THIS IS NOT HOMEWORK IT IS FROM A PRACTICE EXAM GIVEN TO US
My boss have given me assignment to find how a web based application developed
I'm working on a program for class that involves solving the Chinese Postman problem
For an assignment we were given in Data Structures, we had to create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.