Could someone help me with this? I just need to fill in the code here part. Best
ID: 645538 • Letter: C
Question
Could someone help me with this? I just need to fill in the code here part. Best answer gets all the points.
You have been given a Student class. A student pointer, s, has been created for you. The student's name is "Po". The user will enter a new name for Po; you must call the "setName" function to change Po's name to the value given to you by the user. If done correctly, the new name should be shown once.
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Student
{
private:
string name;
public:
Student(string name);
string getName();
void setName(string newName);
~Student();
};
Student::Student(string studentName)
{
name = studentName;
}
string Student::getName()
{
return name;
}
void Student::setName(string newName)
{
name = newName;
}
Student::~Student()
{
}
int main()
{
string name;
cin >> name;
Student* s = new Student("Po");
//
// Code Here
//
cout << s->getName();
return 0;
Explanation / Answer
#include
#include
using namespace std;
class Student
{
private:
string name;
public:
Student(string name);
string getName();
void setName(string newName);
void Print(void);
~Student();
};
Student::Student(string studentName)
{
name = studentName;
}
string Student::getName()
{
return name;
}
void Student::setName(string newName)
{
name = newName;
}
Student::~Student()
{
}
void Student::Print(void)
{
std::cout << "Student name: " << studentOne << ' ';
std::cout << "Student ID: " << IDone << ' ';
std::cout << "Student name: " << studentTwo << ' ';
std::cout << "Student ID: " << IDtwo << ' ';
}
int main()
{
string name;
cin >> name;
Student* s = new Student("Po");
s->setName(name);
cout << s->getName();
return 0;
}