
不知道你的运算规则是什么样的,如果有不同,修改加减乘除运算符重载函数中的计算方法即可。
#include<iostream>#include<stdio.h>
#include<stdlib.h>
using namespace std
class Number{
public:
Number(){
x=y=0
}
Number(int a, int b){
x=a,y=b
}
void display(){
cout<<"x="<<x<<",y="<<y<<endl
}
int getX(){
return x
}
int getY(){
return y
}
Number operator +(const Number &a)
Number operator -(const Number &a)
Number operator *(const Number &a)
Number operator /(const Number &a)
private:
int x
int y
}
inline Number Number::operator +(const Number &a){
return Number(x+a.x, y+a.y)
}
inline Number Number::operator -(const Number &a){
return Number(x-a.x, y-a.y)
}
inline Number Number::operator *(const Number &a){
return Number(x*a.x, y*a.y)
}
inline Number Number::operator /(const Number &a){
return Number(x/a.x, y/a.y)
}
int main()
{
Number num1(16,21),num2(4,3),res
res=num1+num2
res.display()
res=num1-num2
res.display()
res=num1*num2
res.display()
res=num1/num2
res.display()
system("pause")
return 0
}
第一章 VB程序设计概述二、选择题
CADABACDAB CBDBB
第二章 VB可视化编程基础
二、选择题
ABDCACACBCDADAD BDBBB
三、填空题
1.可视 2.LEFT TOPWIDTH HEIGHT
3.按字母序 4.查看代码 5.工具、选项
6.Form1 Font 7.Multiline
8.只读属性
9.工程属性 通用 Form1.show
10.tabindex 0
第三章 VB语言基础
二、选择题
BCADB ADBBCDBCBABAABB
三、填空题
1.整型、长整型、单精度、双精度
2.sin(30*3.14/180)+sqr(x+exp(3))/abs(x-y)-log(3*x)
3.160 今天是:3-22
4.False
5.-4 3 -33 -44
6.“CDEF”
7.(x mod 10)*10+x\10
8.(35\20)*20=20 ( 35 \ 20 ) * 20 = 20
9.x mod 3=0 or x mod 5=0
10.27.6 8.28 1 100 397 true false
第四章 VB程序控制结构
二、选择题
DBCAD ABBAB D25BAC CBACB DAABC
三、填空题
1.正确性、有穷性、可行性、有输入、有输出
2.1 2 3
3.x>7
4.x<amin5.1024 6.117.128.6 I “*”
9.0 100 i+110.2*I 6 “*”
三、编程题
1. Private Sub Form_Click()
Dim n As Integer, i As Integer, s As Long
s = 1
n = Val(InputBox("请输入一个整数:"))
For i = 1 To n
s = s * i
Next i
MsgBox n &"!=" &s
End Sub
2.Private Sub Form_Click()
Dim i%, k%
For j = 3 To 100
k = Int(Sqr(j))
For i = 2 To k
If j Mod i = 0 Then Exit For
Next i
If i >k Then
y$ = y$ &" " &j
End If
Next j
MsgBox y, , "显示质数"
End Sub
3.Private Sub Form_Click()
Dim i%, s%
For i = 1 To 100
s = s + i
Next i
MsgBox "1+2+3+……+100=" &s
End Sub
4.Private Sub Form_Click()
Dim x%, y%
For x = 1 To 50
For y = 1 To 33
z = 100 - x - y
If 2 * x + 3 * y + 0.5 * z = 100 Then
Print "小鸡、公鸡、母鸡分别为:"xyz
End If
Next y
Next x
End Sub
5.Private Sub Command1_Click()
Dim a%, b%, c%, p!, s!
do
a = Val(InputBox("请输入三角形的第一条边"))
if a=-1 then exit do
b = Val(InputBox("请输入三角形的第二条边"))
c = Val(InputBox("请输入三角形的第三条边"))
If a + b >c And a + c >b And b + c >a Then
p = (a + b + c) / 2
s = Sqr(p * (p - a) * (p - b) * (p - c))
Print s
Else
MsgBox "你输入的三边不能构成三角形,请重新输入"
End If
loop
End Sub
6. Private Sub Form_Click()
Dim i As Integer, j As Integer,k as integer
For i = 1 To 8
For k=1 to 8-i
Print spc(3)
Next k
For j = 1 To 2 * i - 1
Print i
Next j
Next i
End Sub
7. Private Sub Form_Click()
Dim i As Integer, j As Integer, k As Integer
For i = 1 To 30
For j = 1 To 30
For k = 1 To 30
If i ^ 2 + j ^ 2 = k ^ 2 Then
Print i &" ^ 2 + " &j &"^ 2 =" &k &"^ 2"
End If
Next k
Next j
Next i
End Sub
8.Private Sub Form_Click()
Dim x As Integer, a As Integer, b As Integer, c As Integer, ss As String
ss = ""
For x = 100 To 999
a = Int(x / 100)
b = Int((x - 100 * a) / 10)
c = x - 100 * a - 10 * b
If a ^ 3 + b ^ 3 + c ^ 3 = x Then
ss = ss &" " &x
End If
Next x
Print ss
End Sub
9.Dim sr As Long, r As Single
sr = Val(InputBox("请输入收入:"))
Select Case sr
Case Is <200
r = 0
Case 200 To 400
r = (sr - 200) * 0.04
Case 400 To 5000
r = sr * 0.04
Case Is >= 5000
r = sr * 0.05
End Select
Print "收入为" &sr &"时所缴纳的税为:" &r
End Sub
10.Private Sub Form_Click()
Dim t As Single, wf As Single
t = Val(InputBox("请输入上网时间:"))
Select Case t
Case Is <10
wf = 50
Case 10 To 60
wf = t * 6
Case Is >= 60
wf = t * 4
End Select
If wf >= 200 Then
wf = 200
End If
Print "上网时间为" &t &"小时上网的费用为:" &wf
End Sub
11. Private Sub Form_Click()
Dim yf As Integer
yf = Val(InputBox("请输入月份"))
Select Case yf
Case 12, 1, 2
MsgBox yf &"月份是冬季"
Case 3, 4, 5
MsgBox yf &"月份是冬季"
Case 6, 7, 8
MsgBox yf &"月份是冬季"
Case 9, 10, 11
MsgBox yf &"月份是冬季"
Case Else
MsgBox "输入错误,请重新输入"
End Select
End Sub
12.if的方法
Private Sub Form_Click()
Dim x As Single, f As Single
x = Val(InputBox("请输入一个数"))
If x <0 Then
f = 2 * x - 1
ElseIf x = 0 Then
f = 4 * x
ElseIf x >0 Then
f = 7 * x - 5
End If
Print "f(" &x &")=" &f
End Sub
Select case语句:
Private Sub Form_Click()
Dim x As Single, f As Single
x = Val(InputBox("请输入一个数"))
Select Case x
Case Is <0
f = 2 * x - 1
Case 0
f = 4 * x
Case Is >0
f = 7 * x - 5
End Select
Print "f(" &x &")=" &f
End Sub
第五章 数组
一、选择题
DCACD DBCDC BADAD
二、填空题
1.名称 Index 2.preserve 3.变体 4.2
3
5.1 2 3 1 4 1 6.1 2 3 2 4 6 7. max max=arr1(i)
三、编程题
1. Option Base 1
Private Sub Form_Click()
Dim a(10) As Integer, i%, temp%
For i = 1 To 10
a(i) = Val(InputBox("请输入第" &i &"个整数"))
Next i
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)