Constructors and Destructors 2

Source: Internet
Author: User

Constructors and Destructors 2.cpp: Defines the entry point for the console application.
Learn to apply for dynamic memory units

#include "stdafx.h"
#include <iostream>
using namespace Std;
Class Student
{
Public
Student ();
Student (int pid, char*pname, float s);
void Modify (float s);
void display ();
~student ();
Private
int id;
Char *name;
Float score;
};


Student::student ()
{
id = 0;
name = new CHAR[11];
strcpy (Name, "No Name");
Score = 0;
}

student::student (int pid, char * pname, float s)
{
id = pid;
name = new Char[strlen (pname) + 1];
strcpy (name, pname);
Score = s;
}

void Student::modify (float s)
{
Score = s;
}

void Student::d isplay ()
{
cout << "id" << ID << endl;
cout << "name" << name << Endl;
cout << "score" << score << Endl;
}

Student::~student ()
{
Delete[] name;
}

int main ()
{
Student S1;
S1.display ();
Student S2 (1511435, "Alen Turing", 95);
S2.display ();
S2.modify (90);
S2.display ();
System ("pause");
return 0;
}

Constructors and Destructors 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.