C语言在loadrunner中应用(3流程控制)-lr_output_message

上一篇 / 下一篇  2007-07-25 10:07:41

今天继续进行c语言在loadrunner中应用的控制流程章节,http://tech.groups.yahoo.com/group/LoadRunnerCN/message/30,本次学习的主要内容是Exercise3.2的内容,通过例子的实际代码的编写来熟悉lr_output_message函数,函数的实现方式是否得当还请指教。
我先是在VC++中写的函数实现的,输出成功后转入loadrunner下运行。
VC++中的实现:
#include <stdio.h>
/************************************************************************/
/* You invest $10,000 in a special account that pays 8% interest
at the end of each year on the beginning balance of the year.
You decide to take your investment out as soon as it doubles.
Write a program that will print out the year, beginning balance,
interest gained for the year and the ending balance for the year.
This program should stop as soon as the ending balance reaches
$20,000. All dollar amounts should be printed to a precision of 2
decimals.
Parameter:
float fBeginBal: beginning balance
float rate: interest at the end of each year
float fEndBalflag: ending balance */
/************************************************************************/
//:Interest.cpp
void RateInterest(){
int iYear = 0;
bool flag = true;
float fBeginBal = 0.00f;
float rate = 0.00f;
float fEndBalflag = 0.00f;
float fInterest = 0.00f;
float fEndBal = 0.00f;

printf("Please input the parameter value! fBeginBal rate and fEndBalflag.\n");
printf("fBeginBal(Begin Balance):");
scanf("%f", &fBeginBal);
printf("rate(Interest rate):");
scanf("%f",&rate);
printf("fEndBalflag(Ending Balance flag):");
scanf("%f",&fEndBalflag);

while (flag)
{
iYear++;
fInterest = fBeginBal*rate;
fEndBal = fBeginBal + fInterest;
printf("Year=%d,Begin Balance=%.2f,Interest=%.2f,Ending Balance=%.2f\n",\
iYear,fBeginBal,fInterest,fEndBal);
fBeginBal = fEndBal;
if(fEndBal>=fEndBalflag)
flag = false;
else
flag = true;
}
}//:~

void main(){
RateInterest();
}

loadrunner中的实现:
void RateIntest(float fBeginBal, float rate, float fEndBalflag){
int iYear = 0;
int flag = 1;
float fInterest = 0.00f;
float fEndBal = 0.00f;
while (flag)
{
iYear++;
fInterest = fBeginBal*rate;
fEndBal = fBeginBal + fInterest;
lr_output_message("Year=%d,Begin Balance=%.2f,Interest=%.2f,Ending Balance=%.2f\n",
iYear,fBeginBal,fInterest,fEndBal);
fBeginBal = fEndBal;
if(fEndBal>=fEndBalflag)
flag = 0;
else
flag = 1;
}
}

Action()
{
RateIntest(10000.00, 0.08, 20000.00);
return 0;
}

在这次练习中发现,Action()充当了VC++中的main()函数的角色,负责函数的调用。而其他函数的定义放在了Action()函数的外部。在loadrunner中参数的传递可以使用lrs_save_param等函数获得的参数来替代。

TAG:

tudou027的个人空间 引用 删除 tudou027   /   2011-05-13 13:39:58
5
引用 删除 wangshuang9504   /   2011-01-11 10:08:37
5
guxingyun的个人空间 引用 删除 guxingyun   /   2007-08-13 20:56:47
今天发现原来loadrunner中的int flag = 1可以使用int flag = TRUE表示
 

评分:0

我来说两句

我的栏目

日历

« 2024-04-26  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 19352
  • 日志数: 22
  • 书签数: 21
  • 建立时间: 2007-05-17
  • 更新时间: 2009-03-01

RSS订阅

Open Toolbar