C++ :: Separating Abstraction And Implementation

May 13, 2012

What is the benefit on separating the abstraction and implementation.

The below code

Code:
class FileProcessor {
public:
virtual void processFile();
};
class DocProcessor : public FileProcessor

[Code] ....

Till now it is fine. suppose DocProcessor and ExcelProcessor uses two big algorithm to process these file types then I still can have subclasses like :

class Algorithm1 : public DocProcessor
{
public:
void algorithm(); //which will be called as per the algorithm class instantiated for to process
};

[Code] ....

same for ExcelProcessor class

Here everything looks fine to me. [ I have not used the bridge pattern to separate the abstraction and implementation]. The only thing i can achieve using bridge is that the number of classes will be reduced if new class like jpgProcessor is introduced or new algorithim is introduced.

Then why it is recommended that always separate the abstraction and implementation...

View 5 Replies


ADVERTISEMENT

C++ :: Separating Routines Into A Separate Implementation And Header File

Oct 18, 2013

I am trying to separate out particular sets of routines into a separate implentation and header file which can be compiled independently to the main program such that the program source consists of a file called customers.h, customers.cpp, and exercise_1_5.cpp

Each of the files should contain the following:

customers.h should contain the definition of the customer structure and the declaration of print_customers.

customers.cpp should contain the implementation (or definition) for print_customers.

exercise_1_5.cpp should contain an include of customers.h and the main program.

This is my original code from a single .cpp file

#include<iostream>
#include<string>
using namespace std;

[Code].....

The error messages I am getting from the compiler on the customers.cpp file:

C:UsersBenDocumentsCS264lab3customers.cpp:5:22: error: variable or field 'print_customers' declared void
C:UsersBenDocumentsCS264lab3customers.cpp:5:22: error: 'customer' was not declared in this scope
C:UsersBenDocumentsCS264lab3customers.cpp:5:32: error: 'head' was not declared in this scope

View 6 Replies View Related

C++ :: Difference Between Encapsulation And Data Abstraction?

Apr 19, 2013

what is main Difference between Encapsulation and Data Abstraction?

View 2 Replies View Related

C :: Separating Number Num-by-num

Nov 7, 2014

I'm trying to separate number num-by-num but according to the example it must show 501 but it shows 510.

Code:

#include <stdio.h>
#include <math.h>
int power(int base,int expo)
{
if ( expo!=1 )
return (base*power(base,expo-1));
}

[code]....

View 1 Replies View Related

C++ :: Separating Numbers Using Reference

Oct 25, 2013

Write a function called breakThree that will accept a 3 digit integer and returns each of the numbers individually. This function will take four paramaters. The first parameter is the three digit number to break apart. Parameters 2 through 4 are passed by reference and will be used to return each of the numbers back to main.

You should make sure that the input into the function is a 3-digit number. If it is not a three digit number the breakThree function should simply return false. If it is a three digit number the breakThree function should break the number apart, and store each of the numbers in the parameters passed by reference.

In main you should get the number from input and then output each of the numbers on a separate line.

What not to use
global variables
cin in breakThree function
cout in breakThree function
goto statements

#include <iostream>
using namespace std;
void separate(int a, int b, int c, int d);
int main(int argc, const char * argv[]) {
int num;

[Code] ....

View 4 Replies View Related

C++ :: Separating Prime Numbers In Group

May 25, 2013

I currently need separating my Prime numbers in group for my assignment. I absolutely do not know how to do this. I am able to find out if the number I used is prime and see how many prime number there are between 1-100 and then 1-1000 (168 primes) and so on. The thing that I need to do is find the number of prime numbers between 101-200, 201-300, 301-400, and so on until 901-100 and have it show on screen. Here is the exact assignment that I’m supposed to find out:

Assignment:

Write a C++ program to calculate and display the number of primes from 1 to 100,000, separated in groups of 100, 10 groups per line. To be more precise, on the first line of output, display the number of primes between 1 and 100, 101 and 200, etc., up to 901 to 1000. Then display the average primes per group. For example, there are 168 primes from 1 to 1000, so the average number of primes per group of 100 (or percentage) is 16.8. Then repeat the process for the groups of 100 between 1001 to 1100, 1101 to 1200, etc., for all groups of 1000 all the way up to 100,000. Your results should be as presented below, under testing.

Testing:

The output of your program should be the following, according to my calculations. Each group (g1, g2, etc.) is the number of primes in a group of 100 numbers. For example in line 1, g1 is the group from 1 to 100, g2 is the group 101 to 200, etc. For line 2, g1 is the group 1001 to 1100, g2 is 1101 to 1200, and g10 is the group from 1901 to 2000.

g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 Average Primes
----------------------------------------------------------------
25 21 16 16 17 14 16 14 15 14 16.8 for 1 to 1000
16 12 15 11 17 12 15 12 12 13 13.5 for 1001 to 2000
14 10 15 15 10 11 15 14 12 11 12.7 for 2001 to 3000
12 10 11 15 11 14 13 12 11 11 12.0 for 3001 to 4000



7 10 5 10 7 11 7 6 11 8 8.2 for 97001 to 98000
7 5 9 9 11 8 7 8 12 11 8.7 for 98001 to 99000
8 11 8 8 7 9 8 10 10 8 8.7 for 99001 to 100000

Total number of primes from 1 to 100000: 9592
Average primes per 1000: 95.92
Percentage of primes from 1 to 100000: 9.59

Here is my code that I have done so far:

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
bool isPrime(long candidate);
long primeCount (long start, long end);

[Code] ....

View 8 Replies View Related

C :: Reading A File In And Separating Line With Strtok Function

May 2, 2013

I'm trying to read a file from the 2nd argument, skipping the first line of the file since it's the name of the columns, and separate each line as a token, by date, subject, startTime, endTime, and location.Here's my code that I got so far:

Code:

void readAppointment(){
if (arg != 2)
exit;
else {
FILE *fp;
fp = fopen( argv[1], "r");
char line[999];

[code]....

View 1 Replies View Related

C++ :: Difference Between Data Abstraction And Data Hiding?

Mar 20, 2014

What is the difference between Data Abstraction and Data Hiding?

View 14 Replies View Related

C :: RSA Implementation And N Modulus

Aug 18, 2013

I have to develop minimalistic implementation of RSA algorithm in C for an embedded device.

I'm doing that for two days but I have run into a problem. The N modulus is the limitation for the maximum message value to be encrypted with RSA.

For example theoretically RSA-1024 can encrypt/decrypt messages 1024 bits long but I still cannot understand how to choose p and q values to produce N == pow(2, 1024).

Is it possible to encrypt/decrypt 1024 bits long messages in practice if the N < pow(2, 1024)?

So far I'm getting the following results

Code:
Encrypting with RSA
d=15689981, e=21, n=16484947
In=16484942, Encrypted= 6074492, Out=16484942 (OK)
In=16484943, Encrypted= 5468920, Out=16484943 (OK)

[Code] ....

View 10 Replies View Related

C++ :: Big Integer Implementation?

Aug 8, 2013

I was trying to implement Big Integer Implementation. I wanted to start with the basic operation of addition. I am having some problems with operator overloading part

/**
BigInteger implementation
*/
#include "conio.h"
#include "iostream"

[Code]....

View 9 Replies View Related

C# :: RSS Reader MVC Implementation

Apr 19, 2014

I was looking at this tutorial: [URL] ..... And I was wondering if implementing it in MVC would be pretty much the same way? How would I display feed items in the views page using?

I tried something like:

ReaderModel Reader = new ReaderModel();
Collection<Rss.Item> List;
List = Reader.GetFeed();
ViewData["RssItems"] = List;

// then in index.cshtml
@foreach(Collection<Rss.Item> items in ViewData["RssItems"]) {
<h3>items.Title</h3>
...
}

I don't think this is right as I'm getting those red error lines...

View 3 Replies View Related

C++ :: Operator New Without Implementation?

Aug 5, 2013

Here is the code,

Code:
class A {
private:
void* operator new(size_t size);
};
int main() {
return 0;
}

The code above compiles fine without errors. But operator new might not have implementation body?

View 3 Replies View Related

C++ :: Gravity Simulator Implementation

Jul 9, 2013

I've been working on creating a simulator to crash two galaxies together as part of a project to stress test a CUDA super computer. I've got a long way to go and am currently just working on correctly simulating n-body gravity functions. First I will use this to simulate the cores of the galaxies (the black holes) and eventually the stars.

So long story short I'm working on the beginnings of a gravity simulator. At this point I found some basic code that works well but doesn't quite give the effect I'm looking for.

The code below only pulls each object towards each other like a spring faster and faster until they shoot off into infinity. I try to give one of my bodies an initial velocity to get it to orbit another, but it always just shoots straight at the other body. I'm thinking I need to factor in inertia so that the initial velocity doesn't just get calculated away really fast by the other calculations.

I'm really looking for a bit of direction to get a real gravity simulator with orbits and such working right so eventually I can scale it up to a galaxy, throw in 100B stars and let the CUDA run for a month..

Code:
void update_galaxies(GLdouble elapsedTime) {
//Calculate gravity simulations
GLdouble r1, r2, r3;
r1 = r2 = r3 = 0.0;

for(unsigned int i = 0; i < galaxies.size(); i++)

[Code] ....

As you can see, I'm calculating all the bodies in a vector called "galaxies" with each other, and doing a basic gravity calculation to it. The update_position function simply takes the calculated acceleration and uses it to calculate the velocity and position based on the "elapsedTime".

I think I need to use the Varlet or Runge-Kutta integration methods, after doing a bit more research.

View 9 Replies View Related

C :: Depth First Search Implementation

Mar 12, 2013

I'm having problems with implementing depth first search.

Code:
6 10 //6vertices 10edges
0 2 //vertex and its adjacent vertex
1 0
1 2
2 3
2 4
3 1
4 1
4 3
4 5
5 3

Output to terminal: 0 2 3 1 4 5
but it should be: 0 2 4 5 3 1

Here's my code:

#include<stdio.h>
#include<assert.h>
/* maxVertices represents maximum number of vertices that can be present in the graph. */
#define maxVertices 100
void Dfs(int graph[][maxVertices], int *size, int presentVertex,int *visited)

[Code] ....

View 1 Replies View Related

C :: Stack Implementation Using Arrays

May 31, 2014

Code:

#include <stdio.h>#include <unistd.h>
#include <stdlib.h>
#define STACKSIZE 100
struct stackk
{
int top;
int items[STACKSIZE];
};
typedef struct stackk *s;

[Code]...

View 1 Replies View Related

C++ :: Stack Implementation With Struct

Apr 7, 2014

I am trying to implement a stack class which has struct data type as its private member. I am getiing the following error ,

bash-3.2$ g++ stack_str_arr.cpp
stack_str_arr.cpp: In member function ‘void stack::push(int)’:
stack_str_arr.cpp:39: error: ‘top’ was not declared in this scope
stack_str_arr.cpp: At global scope:
stack_str_arr.cpp:43: error: no ‘void stack::display()’ member function declared in class ‘stack’

Code:

#include<iostream>
using namespace std;
#define MAX 5
class stack {
public :
stack();

[Code] ....

View 2 Replies View Related

C++ :: 4x4 Matrix Inverse Implementation

Sep 19, 2013

I'm implementing a 4x4 matrix class and all is going well until the inverse function turned up. I'm trying to implement the inverse function, but I can't seem to get my head around it.

I've tried the internet, but found nothing useful. Also, I've looked into source code of other programs/libraries that implement a matrix class, but the code is unreadable.

How I can implement this damn 4x4 inverse function? I know the process of inversion, but putting that process into code is proving quite a challenge.

In addition, I do have some code, but it's unmanageable and inefficient at the moment. If you want to see it, just ask.

Additional question(s): What applications does the inverse matrix have in 3-D?

View 3 Replies View Related

C++ :: Error In MinHeap Implementation?

Nov 22, 2014

I'd like te have a heap which contains any item inserted by me. However, when I insert the values, if I delete the min value of this coded heap twice, I get the min value uncorrect.I could not find where the mistake is.

Code:

void BinaryHeap::percolateDown(int hole) {
int child = hole*2;
while (child < size) {

[Code].....

View 1 Replies View Related

C++ :: Implementation Of Named Class

Sep 12, 2014

I am trying to implement some kind of named class. It would look something like this:

class MyClass {
virtual std::string getName() = 0;
};

And now (what doesn't pass the compilation)

template <std::string NAME> class MyNamedClass {
std::string getName() { return NAME;}
};

And so every time I would like to have a class with a name, I could just do the following:

FinalClass : public MyNamedClass<"FinalClass">{};

The idea is not to have to always reimplement getName(), and just do it concisely in the declaration.

View 7 Replies View Related

C++ :: Hash Function Implementation

Aug 26, 2013

I was trying to implement a hash function in c++. This is just for learning purposes and not for a class project or assignment question. I had some questions before I started programming it:

1) Is it meaningful to have a hash function which maps string to string, string to int, int to int, float to int?
2) Can we have a template implementation which does element to element hashing?

I looked at several sources for a clear understanding of concepts and implementation technique but could not find a good source for reading about hashing.

View 3 Replies View Related

C++ :: Pathfinding Algorithm Implementation

May 11, 2013

I am currently trying to implement a pathfinding algorithm using c++ and opengl. My code so far is shown below:

#define OPEN 1
#define CLOSED 2
#define UNVISITED 3
#define BLOCKED 4
#define HIGHLIGHT 5
#define ONROUTE 6
#define GOAL 7

#define GSIZE 20 // size of tile grid
#define ISTART 15 // index position of starting tile in grid

[Code] ....

View 2 Replies View Related

C/C++ :: Implementation Of A Vector Of Structures

Apr 14, 2014

I created a structure Vector and implement some functions to make the new defined type (vector) dynamically allocated and resized (inspired from the C++ implementation of the dynamic arrays : vector). I need to assign a structure to every vector element but I am not sure that I am doing it right:

here is the structure that I've defined:

typedef struct  {
    void** mem; // to make this parametrizable I want the void* to point to a Structure (referenced with * a pointer)
    unsigned long     elems;
    unsigned long     elemsize; //element size

[Code] ....

I believe I have serious problems with pointers, values and dereferencing a pointer.

View 7 Replies View Related

C++ :: Expression Parser Implementation?

May 5, 2014

How can we implement an expression parser in C++.

View 3 Replies View Related

C++ :: Do A Recursive Implementation Of A Heap

Apr 19, 2013

So I'm going through and trying to do a recursive implementation of a Heap. I keep getting access violations for some reason on my sifts (_siftUp) - even though I'm trying to insert into sub[0] (currSize = 0 in the constructor). I don't think either of my sifts are implemented correctly, are they?

Here's my Heap:

Code:
#ifndef HEAP_H
#define HEAP_H
//**************************************************************************
template<typename TYPE>

[Code].....

View 5 Replies View Related

C :: Implementation Of Graphs In The Form Of Program

Feb 13, 2013

How a graph can be implemented in the form of a c program?

View 2 Replies View Related

C :: Implementation Of Histogram Using Functions And Arrays

Apr 12, 2013

I'm trying to code one of the problems but it really is hard to catch errors for a novice like me at first.

I have to Write a single C function for computing the histogram of a list of nonnegative integers into 4 bins.

The main() function first initializes a positive integer array called List of size N, takes 3 inputs from the user A, B, C (assume 0 < A < B < C), and declares a second integer array Bin[4].

The doBinning function should count the number of elements of List in the interval [0, A) and store it in Bin[0], count of [A, B) in Bin[1], count of elements in [B,C) in Bin[2], and the number of elements >= C in Bin[3]

Code:
#include <stdio.h>
#define N 10
#define M 4
int *doBinning (int source[], int dest[], int a, int b, int c);
int main (){

[Code] ....

Somehow I keep getting error from ptr = doBinning(List[], Bins[]. What am I doing wrong? Code might contain some errors.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved