#include<iostream> #include<string> using namespace std; enum Rank{i3,i5,i7}; class CPU{ public: CPU(){} // CPU(int v,float f,Rank r) v1(v),f1(f),r1(r) // {cout<<"设置了对象"<<endl;} int Getv(){ return v; } float Getf(){ return f; } Rank GetRank(){ return r; } void Setv(int v){ this->v=v; } void Setf(float f){ this->f=f; } void Set(int r){ this->r=(Rank)r; } private: int v; float f; Rank r; }; int main(){ int v; float f; int r; cin>>v>>f>>r; CPU *cpu=new CPU[2]; cpu[0].Setv(v); cpu[0].Setf(f); cpu[0].Set(r); cout<<cpu[0].Getv()<<"伏特\n"<<cpu[0].Getf()<<endl; switch (cpu[0].GetRank()){ case i3:cout<<"i3"<<endl;break; case i5:cout<<"i5"<<endl;break; case i7:cout<<"i7"<<endl;break; } return 0; }
1 #include "stdafx.h" 2 #include<iostream> 3 #include<string> 4 using namespace std; 5 enum CPU_Rank{i3,i5,i7}; 6 CPU_Rank Rank; 7 class CPU{ 8 public: 9 CPU(){} 10 // CPU(int v,float f,Rank r) v1(v),f1(f),r1(r) 11 // {cout<<"设置了对象"<<endl;} 12 int Getv(){ 13 return v; 14 } 15 float Getf(){ 16 return f; 17 } 18 Rank GetRank(){ 19 return r; 20 } 21 void Setv(int v) 22 this->v=v; 23 } 24 void Setf(float f){ 25 this->f=f; 26 } 27 void Set(int r){ 28 this->r=r; 29 } 30 private: 31 int v; 32 float f; 33 Rank r; 34 }; 35 int main(){ 36 int v; 37 float f; 38 Rank r; 39 cin>>v>>f>>r; 40 CPU *cpu=new CPU[2]; 41 cpu[0].Setv(v); 42 cpu[0].Setf(f); 43 cpu[0].Set(r); 44 cout<<cpu[0].Getv<<"伏特\n"<<cpu[0].Getf<<endl; 45 switch (cpu[0].GetRank()){ 46 case i3:cout<<"i3"<<endl;break; 47 case i5:cout<<"i5"<<endl;break; 48 case i7:cout<<"i7"<<endl;break; 49 } 50 return 0; 51 }
时间: 2024-11-13 09:44:19