首页 > 其他分享 >cpp: create class

cpp: create class

时间:2023-04-04 20:23:34浏览次数:34  
标签:int create piginfo PigName cpp include class PigInfo

PigInfo.h

#ifndef PIGINFO_H
#define PIGINFO_H

#include <iostream>
#include<string.h>
#include<math.h>

using namespace std;

/*
实体类
https://learn.microsoft.com/zh-cn/cpp/standard-library/cpp-standard-library-header-files?view=msvc-170
https://learn.microsoft.com/en-us/cpp/cpp/header-files-cpp?view=msvc-170
*/
class PigInfo
{
private:
	string PigName;
	int PigWeight;

public:
	void SetPigName(string pigName)
	{
		PigName = pigName;
	}

	void SetPigWeight(int pigWeight)
	{
		PigWeight = pigWeight;
	}

	string getPigName()
	{
		return PigName;
	}

	int getPigWeight()
	{
		return PigWeight;
	}
	//构造函数
	//PigInfo(string pigname, int pigweight);

	void ShowInfo();

};


/*
构造函数
PigInfo::PigInfo(string PigName, int PigWeight)
{
	//构造函数函数体内进行赋值操作
	this->PigName = PigName;
	this->PigWeight = PigWeight;
}*/
/*
*
*/
void PigInfo::ShowInfo()
{
	cout << "小猪名称:" << this->getPigName() << ",重量:" << this->getPigWeight() << endl;
	//cout << "" << this->getPigWeight() << endl;
}


#endif

  

// cppdemo.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include<string.h>
#include<math.h>
#include<list>
#include "PigInfo.h"


using namespace std;

class Rectangle {
	int width, height;
public:
	void set_values(int, int);
	int area() { return width * height; }
};

void Rectangle::set_values(int x, int y) {
	width = x;
	height = y;
}




int main()
{
    //std::cout << "Hello World!涂聚文\n";

	/*Rectangle rect;
	rect.set_values(3, 4);
	cout << "area: " << rect.area();
    */
	list<PigInfo> pigInfoList;

	PigInfo piginfo;
	string name;
	int weight;

	//piginfo.SetPigName("geovindiu");
	//piginfo.SetPigWeight(25);
	for (int i = 1; i < 4; i++)
	{
		std::cout << "请输入第"<<i<<"只小猪的名称" << endl;
		cin >> name;
		std::cout << "请输入第"<<i<<"只小猪的重量" << endl;
		cin >> weight;
		piginfo.SetPigName(name);
		piginfo.SetPigWeight(weight);
		//piginfo.ShowInfo();
		pigInfoList.push_back(piginfo);

	}
	cout << "名称:" << "\t" << "重量:" << "\t" << endl;
	for (auto info : pigInfoList)
	{
		cout <<"\t\t"<< info.getPigName() << "\t"<<info.getPigWeight() << endl;
	}

	system("pause");
	return 0;
	

}

  

 

标签:int,create,piginfo,PigName,cpp,include,class,PigInfo
From: https://www.cnblogs.com/geovindu/p/17287791.html

相关文章

  • 属性指令之class和style
    目录说明classstyle说明class与style本身是属性指令,但是他们比较特殊,应用更广泛。#class:class='变量' 变量可以为:字符串、数组、对象 推荐使用数组,因为class可以使用多个参数#style:style='变量' 变量可以为:字符串、数组、对象 推荐使用对象class#先......
  • Chisel3 使用 DPI-C,发现在 Chisel 环境下 printf 没问题,但是 set_pc 死活传不到 cpp
    大概率是因为你使用了SignExt之类的封装这类封装只会把”值“传给DPI-C,而不会把线连给DPIC,即,传过去的是调用set_pc时的值,而不是引用这样会造成CPP获取不了相应线路的指针 如下图     这些也是错的......
  • DecisionTreeClassifier&DecisionTreeClassRegression
    DecisionTreeClassifierfromsklearn.datasetsimportload_wine#红酒数据集fromsklearn.treeimportDecisionTreeClassifier,export_graphviz#决策树,画树fromsklearn.model_selectionimporttrain_test_split#数据集划分importgraphvizimportmatplotlib.pyplo......
  • 类(class)和结构(structure)的认识
    本文复制了MSDNlibrary的原话,觉得它说得有道理,狠经典原话:类和结构是.NETFramework中的常规类型系统的两种基本构造。两者在本质上都属于数据结构,封装着一组整体作为一个逻辑单位的数据和行为。数据和行为是该类或结构的“成员”,它们包含各自的方法、属性和事件等(本主题后......
  • 加载spring配置的两个方法AnnotationConfigApplicationContext()和getRootConfigClass
    在Spring中,AnnotationConfigApplicationContext类和AbstractAnnotationConfigDispatcherServletInitializer类中的getRootConfigClasses()方法都是用来加载Spring配置类,并创建Spring容器的。因此,它们的作用是相似的,都是用来配置Spring容器的。但是,它们的使用场景和......
  • 【已解决】configure: error: C++ compiler cannot create executables
    1.背景 centos7在升级gccconfigure的时候出现的问题A100-01-$build#../configure--prefix=/usr/local/gcc--enable-threads=posix--disable-checking--disable-multilib--enable-languages=c,c++checkingbuildsystemtype...x86_64-pc-linux-gnucheckinghosts......
  • 修改头像,CreateModelMixin, RetrieveModelMixin, UpdateModelMixin内部的方法进行重写
    1.假设GET请求和POST请求,用的序列化类不一样,如何处理__ser.py 2.假设GET请求和POST请求,用的序列化类不一样,如何处理__views.py  3.假设GET请求和POST请求,用的序列化类不一样,如何处理总结  4.用户注册测试  5.查询用户名和用户头像  6.修改用户头像  7......
  • 类型类Type classes(第一部分)类约束 Eq、Ord、Show、Read、Enum、Num、Integral、Float
    类型类Typeclasses是一种定义某种行为的接口。如果类型是类型类的成员,则意味着类型支持并实现了类型类定义的行为。类约束==函数的类型,如下:type(==)(==)::Eqa=>a->a->Bool=>符号定义了一个类约束,==函数接受两个相同类型的形参,并返回Bool类型。这两个形参的类型......
  • junit单元测试报错:java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
    今天在复习的时候对对一些知识点进行巩固,用到了junit-4.12.jar,手动导入jar包,然后运行然后报错:java.lang.NoClassDefFoundError:org/hamcrest/SelfDescribing。刚开始我以为代码错了,看了看发现不是代码的问题,是导包的问题。然后查询了百度,发现了是版本的问题:然后说换个低版本的就......
  • java reflection exception--can not access a member of class XXX with modifiers "
    Ifyoutrytovisitthevalueofanobject'sprivatefieldusingreflection,suchasField#getorField#set,youshouldcallField#setAccessibleahead.lookatthesampleprogrambelow.ItworkswhenIrunit.Field[]fields=ref......