[ create a new paste ] login | about

Link: http://codepad.org/j5Wbhl69    [ raw code | output | fork ]

C++, pasted on May 6:
--------------------main.cpp-----------------------------
#include <iostream>
#include "struct.h"
#include "class.h"
#include "init.h"
#include "const.h"


int main(int argc, char** argv)
{
	str p;
        str *pp;
        pp = new str;
	init(&p);
	mem(&p);
	show(&p);
	std::cout << &p<<std::endl;
	std::cout << pp <<std::endl;
	delete pp;
	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)
{
	p->A=1.0;
	p->E=1.0;
	std::cout<<"B=";
	std::cin >>p->B;
	std::cout<<"C=";
	std::cin >>p->C;
	std::cout<<"D=";
	std::cin >>p->D;
	
}

---------------------------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;


Output:
1
2
3
4
5
6
Line 19: error: struct.h: No such file or directory
Line 18: error: class.h: No such file or directory
Line 17: error: init.h: No such file or directory
Line 18: error: const.h: No such file or directory
Line 1: error: expected unqualified-id before '--' token
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: