change c code to c++

can someone pls help me changing this code to c++






#include <stdio.h>
#include <string>



typedef struct {
char name[32],
surname[64];
unsigned char age;
} Student;



struct StudentItem;



typedef struct StudentItem {

struct StudentItem *next;
Student item;

} StudentItem;




void Student_Input(Student *st) {
printf("Enter Name: "); scanf("%s", &st->name);
printf("Enter Surname: "); scanf("%s", &st->surname);
printf("Enter Age: "); scanf("%d", &st->age);
}

void Student_Output(Student *st) {
printf("| %16s | %24s | %3d |\n", st->name, st->surname, st->age);
}

const char horzLine[] = "-------------------------------------";

void Students_Separator() {
printf("+------------------+--------------------------+-----+\n", horzLine, horzLine, horzLine);
}

void Students_Output(StudentItem *list) {
Students_Separator();
printf("| %16s | %24s | %3s |\n", "Name", "Surname", "Age");
Students_Separator();

StudentItem *item = list;

while (item) {
if (item->item.surname[0]) { // checks whether string `surname` is not empty
Student_Output(&item->item);
item = item->next;
}
}

Students_Separator();
}



StudentItem *Student_New(StudentItem *root) {
StudentItem *item = (StudentItem *) malloc( sizeof(StudentItem) ); // Create the item
if (root)
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <string>
using namespace std;


class Student {
	unsigned age;
public:

	Student() {
		cout << "Enter Name: "; getline(cin, name);
		cout << "Enter Surname: "; getline(cin, surname);
		cout << "Enter Age: "; cin >> age;
	}
	
	Student (Student &other)
	: age(other.age)
	, name(other.name)
	, surname(other.surname)
	{}
	
	string name, surname;
};

class StudentItem{

public:
	StudentItem *next;
	Student* item;
	
	StudentItem()
	: next(nullptr)
	, item(nullptr)
	{}
	
	StudentItem(StudentItem &other)
	: next(other.next)
	, item(other.item)
	{}
};


Student *Student_Input() {
	return new Student();
}

void Student_Output(Student *st) {
	//printf("| %16s | %24s | %3d |\n", st->name, st->surname, st->age);
}

const string horzLine("-------------------------------------");

void Students_Separator() {
	//printf("+------------------+--------------------------+-----+\n", horzLine, horzLine, horzLine);
}

void Students_Output(StudentItem &list) {
	Students_Separator();
	//printf("| %16s | %24s | %3s |\n", "Name", "Surname", "Age");
	Students_Separator();

	StudentItem *item = &list;

	while (item) {
		if (!item->item->surname.empty()) { // checks whether string `surname` is not empty
			Student_Output(item->item);
			item = item->next;
		}
	}

	Students_Separator();
}

int main(){}
thnx very much
Topic archived. No new replies allowed.