定义一个CForm窗体类,在该类中包括:
(1)成员变量:title(窗体标题),width(窗体宽度),height(窗体高度);
(2)合适的构造函数和析构函数,实现调用构造函数和析构函数的输出语句;
(3)成员函数:SetTitle()用来给标题赋值;SetSize()用来给窗体宽度和高度赋值;Show()显示窗体标题和尺寸信息;//参数需根据要求定义。
(4)要求在成员函数中使用对象指针this。
(5)要求使用多文件编程。(文件名例如:CForm.h,CForm.cpp,FormApp.cpp)
已知测试函数如下:
int main()
{
CForm form1;
form1.SetTitle("My Form");
form1.SetSize(400,350);
form1.Show();
CForm form2("Your Form",600,480);
form2.Show();
return 0;
}
#define _CRT_SECURE_NO_WARNINGS#include <iostream>
#include <cstring>
using namespace std;
#include "CForm.h";
int main()
{CForm form1;form1.SetTitle("My Form");form1.SetSize(400, 350);form1.Show();CForm form2("Your Form", 600, 480);form2.Show();return 0;
}
头文件
#pragma once
#include <iostream>
#include <iostream>
#include <string>using namespace std;
class CForm
{
public:CForm(string t, double w, double h);CForm();~CForm();void SetTitle(string t);void SetSize(double w, double h);void Show();private:string title;double width;double height;
};
源文件
#include "CForm.h";
CForm::CForm()
{}
CForm::CForm(string t, double w, double h)
{title = t;width = w;height = h;cout << "构造函数被调用" << endl;
}CForm::~CForm()
{cout << "析构函数被调用" << endl;
}
void CForm::SetTitle(string t)
{this->title = t;
}
void CForm::SetSize(double w, double h)
{this->width = w;this->height = h;
}
void CForm::Show()
{cout << "title:" << this->title << " " << "width:" << this->width << " " << "height:" << this->height << endl;
}