--------------------main.cpp-----------------------------
#include <iostream>
#include "struct.h"
#include "class.h"
#include "init.h"
#include "const.h"
int main(int argc, char** argv)
{
str *p;
init(p);
mem(p);
show(p);
std::cout << p->A<<std::endl;
std::cout << p->E <<std::endl;
return 0;
}
---------------------struct.h-------------------
//構造体
#ifndef STRUCT_H
#define STRUCT_H
typedef struct
{
double A;
double B;
double C;
double D;
double E;
}str;
#endif
-----------------------init.h-------------------
//init.h
#ifndef INIT_H
#define INIT_H
#include "struct.h"
void init(str *p);
#endif
-----------------------init.cpp-------------------
void init(str *p)
{
str DATA;
DATA.A=1.0;
DATA.E=1.0;
std::cout<<"B=";
std::cin >>DATA.B;
std::cout<<"C=";
std::cin >>DATA.C;
std::cout<<"D=";
std::cin >>DATA.D;
p=&DATA;
}
---------------------------class.h-----------------
//class.h
#ifndef CLASS_H
#define CLASS_H
#include "struct.h"
void mem(str *p);
void show(str *p);
#endif
---------------------------class.cpp----------------------
using namespace std;
void mem(str *p)
{
p->A=p->B*p->C;
p->E=p->D*(A1+A2);
}
void show(str *p)
{
cout<<p->A<<"="<<p->B<<"*"<<p->C<<endl;
cout<<p->E<<"="<<p->D<<"*"<<"("<<A1<<"+"<<A2<<")"<<endl;
}
------------------------------const.h-----------------
//const.h
static const double A1=20.0;
static const double A2=30.0;