一.求圆的周长
//
// main.c
// cdemo
//
// Created by liyongkai on 2021/6/6.
//
#include <iostream>
using namespace std;
const double pi = 3.14;
class Cicle {
public:
//成员属性 半径
int m_r;
//成员函数
double calculate() {
return 2 * pi * m_r;
};
};
int main(int argc, const char * argv[]) {
Cicle c;
c.m_r = 10;
cout << "c的周长为:" << c.calculate() << endl; //c的周长为:62.8
return 0;
}
二.学生类
//
// main.c
// cdemo
//
// Created by liyongkai on 2021/6/6.
//
#include <iostream>
using namespace std;
class Student {
public:
string m_name;
int m_id;
void setName(string name) {
m_name = name;
}
void setID(int ID) {
m_id = ID;
}
void showInfo() {
cout << "姓名:" << m_name <<" "<< "学号:" << m_id << endl;
}
};
int main(int argc, const char * argv[]) {
Student std;
std.setName("张三");
std.setID(100);
cout << "姓名:" << std.m_name <<" "<< "学号:" << std.m_id << endl;
//姓名:张三 学号:100
std.showInfo();
//姓名:张三 学号:100
return 0;
}
三.
网友评论