according to the following simple task:
Write a c++ class called 'student' with
Data members:
name(char type),
marks1,marks2 (integer type)
The program asks the user to enter name and marks. Then calcMedia()
calculates the media note and disp() display name and total media mark on
the screen in different lines.
Below is the given solution, however, it does not compile. Would like to see a different approach to the solution provided if possible.
In function 'int main()':
33:14: warning: 'nam' is used uninitialized in this function [-Wuninitialized]
What actually most likely mean is that your program has run-time errors.
Your first issue is that you are trying to put user input into an invalid pointer (nam).
name(char type),
If that is what your text says, then you should be using char, not char*. But that only allows you to enter one character, not a string. I assume you wrote it down wrong, and your assignment does want you to use c-strings, which is unfortunate.
Anyway, an easy fix would be to change it so that you have an actual char array: