首页 > 其他 > 详细

实验3

时间:2019-04-17 20:44:02      阅读:125      评论:0      收藏:0      [点我收藏+]

part 2

#ifndef GRAPH_H
 2 #define GRAPH_H
 3 
 4 
 5 class Graph {
 6     public:
 7         Graph(char ch, int n);  
 8         void draw(); 
 9     private:
10         char symbol;
11         int size;
12 };
13 
14 
15 #endif
16 
17  
18 #include "graph.h" 
19 #include <iostream>
20 using namespace std;
21 Graph::Graph(char ch, int n): symbol(ch), size(n) {
22 }
23 
24 void Graph::draw() {
25     int x=size*2-1;
26     int i,line;
27     for(line=1;line<=size;line++)
28     {
29         for(i=1;i<=x;i++)
30         {
31             if(i>size-line&&i<size+line)
32             cout<<symbol;
33             else cout<<" ";
34         }
35         cout<<endl;
36      } 
37 }
38 
39 #include <iostream>
40 #include "graph.h"
41 using namespace std;
42 
43 int main() {
44     Graph graph1(*,5);
45     graph1.draw();
46     
47     system("pause");
48     system("cls");
49     
50     Graph graph2($,7);
51     graph2.draw();
52     
53     return 0; 
54 } 
技术分享图片

技术分享图片

 

 

part 1

技术分享图片

 

 

part 3

#include<iostream> using namespace std; class Fraction { public: Fraction(int top0=0,int bottom0=1){ top=top0; bottom=bottom0; cout<<"top="<<top<<" "<<"bottom="<<bottom<<endl; } void show(); Compare(Fraction & c); private: int top; int bottom; }; void Fraction::show(){ int add,sub,mul,div; add=top+bottom; sub=top-bottom; mul=top*bottom; div=top/bottom; cout<<"add="<<add<<endl; cout<<"subtract="<<sub<<endl; cout<<"multiply="<<mul<<endl; cout<<"divide="<<div<<endl; cout<<"fraction="<<top<<"/"<<bottom<<endl; } Fraction::Compare(Fraction & c){ if(top/bottom>c.top/c.bottom) cout<<top/bottom<<">"<<c.top/c.bottom<<endl; else cout<<top/bottom<<"<"<<c.top/c.bottom<<endl; } int main() { Fraction a; a.show(); Fraction b(3,4); b.show(); Fraction c(5); c.show(); c.Compare(b); return 0; }
技术分享图片

 


  

总结:本次实验主要是对多文件的调试和编辑,正确使用多文件的方式会使代码变得整洁清晰并且方便许多。

实验3

原文:https://www.cnblogs.com/suifeng823/p/10725816.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!