Commit 09a3b223 by 李楚霏

work08

parent 8f69997b
#include<iostream>
#include<cstring>
using namespace std;
struct candyBar
{
/* data */
char name[30];
double weight;
int colorie;
};
void setCandyBar(candyBar&, const char*n = "aabb", double w = 2.10, int c= 19);
void printBar(candyBar&);
int main() {
candyBar CB;
setCandyBar(CB);
char name[]="munch";
double weight = 12.11;
int colorie = 10;
setCandyBar(CB,name, weight, colorie);
printBar(CB);
return 0;
}
void setCandyBar(candyBar &cb, const char* n, double w, int c) {
strcpy(cb.name, n);
cb.weight = w;
cb.colorie =c;
}
void printBar(candyBar &cb) {
cout<<cb.name;
cout<<cb.weight;
cout<<cb.colorie<<endl;
}
\ No newline at end of file
#include<iostream>
using namespace std;
#include<cstring>
struct stringy
{
/* data */
char * str;
int ct;
};
void set(stringy&, const char* test);
void show(stringy&, int num = 2);
void show(const char* test = "aabb", int num = 3);
int main() {
stringy beany;
char testing[] = "Reality isn't what it used to be";
set(beany, testing);
show(beany);
show(beany,2);
testing[0]='D';
testing[1]='u';
show(testing);
show(testing, 3);
show("Done!");
return 0;
}
void set(stringy& s, const char* test) {
strcpy(s.str, test);
}
void show(stringy& s, int num) {
s.ct = num;
}
void show(const char* test, int num) {
cout<<"test:"<<test;
cout<<num<<endl;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment