面向对程序设计中有分析程序运行结果的题不会,请高手赐教!!急急急!!!

面向对程序设计中有分析程序运行结果的题不会,请高手赐教!!急急急!!!,第1张

建议你自己运行下,根据结果再分析为什么,这样对你才有帮助。

1 第一次循环j循环,输出一行5个“”,然后换行;

第二次循环i=1,再执行j循环,输出4个“”,换行,以此类推。

当i=4时,j循环一次,输出1个“”。换行,循环结束。

最笨的办法就是自己计算每一个循环,然后就能得出规律了。

2A x("xuxiaokai");//创建A的对象x,调用构造函数,将成员变量a初始化,并输出,然后调用析构函数。

A y=new A("weirong");动态创建A的对象y,后结果与x的初始化相同,只是需要delete y,否则继续占用内存。

建议认真学习下new和delete

3 结果如下:

i=0时,case'+' k=10+4=14;

i=1;case'-' k=10-4=6;

i=2;case'' k=104=40;

i=3;case'/' k=100/4=25;

i=4;a[4]=@,执行default语句

1+2+3+4+……+100:

dim i as integer,s as long

for i = 1 to 100

s=s+i

next

msgbox s

1

Private Sub Form_Load()

Dim s As String, l As String, oldl As Long, wordc As Long

s = InputBox("输入句子", "输入")

s = Replace(s, ", ", ",")

s = Replace(s, " ", "")

s = Replace(s, ": ", ":") '统一格式 避免重复统计

oldl = Len(s) '记录句子长度

l = Replace(s, " ", "") '把空格删除

wordc = wordc + oldl - Len(l) '计算减少长度

l = Replace(s, ",", "") '把逗号删除

wordc = wordc + oldl - Len(l) '计算减少长度

l = Replace(s, "", "") '把点删除

wordc = wordc + oldl - Len(l) '计算减少长度

l = Replace(s, ":", "") '把冒号删除

wordc = wordc + oldl - Len(l) '计算减少长度

MsgBox "单词数: " & CStr(wordc)

End Sub

2

Private Sub Form_Load()

Dim s As String, ol As Long, c As Long

s = InputBox("输入句子", "输入")

ol = Len(s)

s = Replace(s, " the", "")

s = Replace(s, "The", "")

s = Replace(s, "The ", "")

c = (ol - Len(s)) / 4

ol = Len(s)

s = Replace(s, " the ", "") '不能仅仅替换the。

MsgBox "the个数: " & CStr((ol - Len(s)) / 5 + c)

End Sub

'注意 以上两个都有很多复杂判断的 这里省略了一下 可以应付大多数统计

3

Dim n As Integer

Dim num As Integer

num = 1

For n = 1 To 9

num = (num + 1) 2

Next

MsgBox "桃子总共" & num & "个"

4

Private Sub Form_Load()

Const c As Long = 4

Dim i As Integer, s As String

For i = 1 To c

s = s & vbCrLf & Space((c - i) 2 + 1) & PrintRepeat(i 2 - 1, " ")

Next

For i = (c - 1) To 1 Step -1

s = s & vbCrLf & Space((c - i) 2 + 1) & PrintRepeat(i 2 - 1, " ")

Next

MsgBox s

End Sub

Function PrintRepeat(Count As Long, str As String) As String

Dim i As Integer

For i = 1 To Count

PrintRepeat = PrintRepeat & str

Next

End Function

'第四题你可以修改c看看其它效果

以上就是关于面向对程序设计中有分析程序运行结果的题不会,请高手赐教!!急急急!!!全部的内容,包括:面向对程序设计中有分析程序运行结果的题不会,请高手赐教!!急急急!!!、VB程序设计解题分析,仅仅是照着最初的解题分析写一下。、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10171943.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-06
下一篇 2023-05-06

发表评论

登录后才能评论

评论列表(0条)

保存