# 關於C++問題,我...看不懂題意,請給我個提示!!

1.試撰寫一函數,當函數指接收到一個引數或一個字串時,則函數輸出該字串.若函數接受第2個引數,一個非0整數(假設是n),則函數輸出該字串n次. 撰寫時將以上方法寫成函數.

2.以下為golf.h標頭檔:

//golf.h

const int Len = 40;

struct golf

{

char fullname[Len];

int handicap;

};

//function solicits name and handicap from user

//return 1 if name is entered, 0 if is empty string

int setgolf(golf & g);

//function sets golf structure to provided name, handicap

void Setgolf(gollf & g, const char*name, int hc);

//function resets handicap to new value

void handicap(gollf & g, int hc);

//function displays contents of golf structure

void showgolf(const golf & g);

Update:

Rating
• ?
Lv 5

1.試撰寫一函數,當函數指接收到一個引數或一個字串時,則函數輸出該字串.若函數接受第2個引數,一個非0整數(假設是n),則函數輸出該字串n次. 撰寫時將以上方法寫成函數.

#include<string.h>

#include<iostream.h>

#include<stdlib.h>

void fun(char str[])

{

char m[1];

static char string[20];

int n;

static int count=0;

if(count==0)

{

for(int i=0;i<20;i++)

{

string[i]=str[i];

}

cout<<str<<endl;

count++;

}

else

{

m[0]=str[0];

n=atoi(m);

for(int a=0;a<n;a++)

{

cout<<string<<endl;

}

}

}

void main()

{

char str[20];

int n=0;

do{

cin.getline(str,20);

fun(str);

n++;

}while(n==1);

}

Source(s): 自己