Created
May 20, 2015 10:59
-
-
Save MasazI/f5d7ce4be3099b8cb78f to your computer and use it in GitHub Desktop.
Inheritance_virtuail_function.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// inheritance.cpp | |
// CplusplusPractice | |
// | |
// Created by masai on 2015/05/20. | |
// Copyright (c) 2015年 masai. All rights reserved. | |
// | |
#include <iostream> | |
#include "Stream.hpp" | |
#include "InputStream.hpp" | |
#include "ArrayStream.hpp" | |
using namespace std; | |
bool Average(Stream& stream){ | |
int count; | |
double avr = 0; | |
for(count = 0; stream.Set(); ++count){ | |
avr += stream.Get(); | |
} | |
if(count == 0){ | |
return false; | |
} | |
avr /= count; | |
cout << "average is " << avr << endl; | |
count = 0; | |
return true; | |
} | |
int main(){ | |
// ArrayStream | |
static const double array1[] = {1, 2, 3, 4, 5, 6, -1}; | |
static const double array2[] = {2, 4, 5, 6, 1, -1}; | |
static const double* const array[] = {array1, array2}; | |
// sizeは全体のメモリサイズ / 要素(最初の一つ目)のメモリサイズ | |
static const int size = sizeof array / sizeof *array; | |
for(int i = 0; i < size; ++i){ | |
ArrayStream stream(array[i]); | |
if(! Average(stream)){ | |
//break; | |
} | |
} | |
// InputStream | |
while(true){ | |
InputStream stream; | |
if(! Average(stream)){ | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment