struct.cpp
#include <iostream>
using namespace std;
struct inflatable
{
string name;
int age;
float weight;
};
struct new_struct
{
string name;
int age;
string addr;
} meowrain = {
"meowrain",
18,
"China"},
linus = {"linux", 40, "America"};
struct {
int x;
int y;
int sum(int x,int y) {
return x+y;
}
}sum;
int main(void)
{
inflatable duck;
duck.name = "mike";
duck.age = 5;
duck.weight = 1.5;
inflatable chicken = {
"john",
6,
1.3};
inflatable dog{"mi", 3, 4};
inflatable cat;
cat = dog;
cout << chicken.age << endl;
cout << dog.name << endl;
cout << cat.name << endl;
cout << meowrain.addr << endl;
cout << linus.addr << endl;
sum.x = 10;
sum.y = 10;
int m = sum.sum(sum.x,sum.y);
cout << m << endl;
}
StructArray.cpp
#include <iostream>
using namespace std;
struct inflatable
{
string name;
int age;
float weight;
};
struct new_struct
{
string name;
int age;
string addr;
} meowrain = {
"meowrain",
18,
"China"},
linus = {"linux", 40, "America"};
struct {
int x;
int y;
int sum(int x,int y) {
return x+y;
}
}sum;
int main(void)
{
inflatable duck;
duck.name = "mike";
duck.age = 5;
duck.weight = 1.5;
inflatable chicken = {
"john",
6,
1.3};
inflatable dog{"mi", 3, 4};
inflatable cat;
cat = dog;
cout << chicken.age << endl;
cout << dog.name << endl;
cout << cat.name << endl;
cout << meowrain.addr << endl;
cout << linus.addr << endl;
sum.x = 10;
sum.y = 10;
int m = sum.sum(sum.x,sum.y);
cout << m << endl;
}