BEGINNER: Virtual function and polymorphic

Pages: 12
Can someone give me tips and pointers about how i should approach this assignment and steps I need to do ?

Thanks


In this module you learned how to create polymorphic code using virtual functions.

A file filter reads an input file, transforms it in some way, and writes the results to an output file. Write an abstract file filter class that defines a pure virtual function for transforming a character. Create one subclass of your file filter class that performs encryption, another that transforms a file to all uppercase, and another that creates an unchanged copy of the original file.

The class should have a member function

void doFilter(ifstream &in, ofstream &out)

that is called to perform the actual filtering. The member function for transforming a single character should have the prototype

char transform(char ch)

The encryption class should have a constructor that takes an integer as an argument and uses it as the encryption key.
Can someone give me tips and pointers about how i should approach this assignment and steps I need to do ?


Sure can.

As far as tips are concerned. Read the instructions you have been given because step by step they tell you exactly what to do.

As far as pointers are concerned.
In this module you learned how to create polymorphic code using virtual functions.
and that generates the last tip you need - Revise that module.

nice try
Oh shit. I didn't see who the author was.

mrs black is back! Where's namby pamby and ImageMan retweeter to pander to the resident whiner.
get a life
Get an education ... you're not doing much good at it so far by weaseling and whining.
im in college getting an education. trying finding a life
What have you tried so far?
The only thing i can provide in terms of code is the pre processor directives and variables. I don't know how to do things in this assignment such as classes, etc
your assignment wrote:
In this module you learned how to create polymorphic code using virtual functions.

But it says you did use virtual functions, which implies the use of classes. So is your assignment mistaken?

Tutorials on classes from cplusplus.com:
http://www.cplusplus.com/doc/tutorial/classes/
http://www.cplusplus.com/doc/tutorial/templates/
http://www.cplusplus.com/doc/tutorial/classes2/
http://www.cplusplus.com/doc/tutorial/inheritance/
http://www.cplusplus.com/doc/tutorial/polymorphism/ (this would be the most relevant one, although if you don't know how to write a class, I suggest starting from the beginning)
Last edited on
That the assignement instructions. I read about virtual functions but doesn't mean i actually understood it.
I'm getting an error at line 44 and 46. Can someone hlep me fix/debug this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//Charles Blackwell CIS 221 M6
#include <iostream>
#include <fstream>
#include <string>
#include <time.h>
#include <iomanip>
#include "filter.h"
using namespace std;

int main()
{
	ifstream inFile;
	ofstream outFile;
	string inFileName, outFileName;

	// Ask user to enter the names of files to encrypt and decrypt.
	cout << "Enter name of file to filter: ";
	cin >> inFileName;
	cout << "Enter name of file to receive the filtered text: ";
	cin >> outFileName;

	inFile.open(inFileName);
	if (!inFile)
	{
		cout << "The file " << inFileName
			<< " cannot be opened.";
		exit(1);
	}
	outFile.open(outFileName);
	if (!outFile)
	{
		cout << "The file " << outFileName
			<< " cannot be opened.";
		exit(1);
	}

	//int key;
	//// Ask user to enter an encrytion key
	//cout << "Enter an encryption key: ";
	//cin  >> key;
//
	//Encrypt test(key);
	//Upper test;
	Copy test;

	test.doFilter(inFile, outFile);

	inFile.close();
	outFile.close();

	return 0;
}
> im in college getting an education
Who's paying for it - you, your parents, or taxpayers at large?

Is this your major? Where in your imagination, you pass with flying colours and a well paid job that enables you to pay off your debts awaits. Based on the level of course material you say you've "studied" and your apparent skill level, that edifice is going to come crashing down at the first closed book assignment/exam.

Seriously, if it's your money on the table and this is your plan to pay it back - you're screwed.

> The only thing i can provide in terms of code is the pre processor directives and variables.
That sounds about like the first lesson.

> In this module you learned how to create polymorphic code using virtual functions.
Mmm, your palindrome fiasco was M5 and this is M6.
Which was the first one you started to have some doubts about knowing fully - M2?

> I read about virtual functions but doesn't mean i actually understood it.
Well keep reading until you think you understand it.
Then keep doing exercises until you actually understand it.

It's like you're standing around in the kitchen hoping to become a master chef, just from observing others working and reading a few menus. It's not going to happen.

Real kitchen mastery comes from a long list of knife wounds, over and under cooked dishes and maybe even the occasional fire.

Programming is the same - without the physical pain and bad smells.
It's a lot of frustration, study, going back over past examples, trying different things.

Not running to a forum every time you get a syntax error.

> I'm getting an error at line 44 and 46. Can someone hlep me fix/debug this
It's a meaningless waste of a post without knowing what's in the invisible filter.h file.
Rude
Can someone hlep me fix/debug this


Sure. The problem is at line 44 and line 46. Delete those lines and you are good to go.


That was sarcasm by the way. Obviously we cannot help you if you do not provide all the code. What is "Copy?" What is the definition of that class? What is the definition of the doFilter method? What error messages are you receiving? Providing none of this information while expecting us to fix your problem is asinine.
Because this is all the code I have. Also, I guess you skipped over the part at the TOP of the page that says "Beginner"
Hi, I am a beginner, can you teach me how to build a nuclear powered rocketship in my basement?

That is what you ask here. A week ago you could not write a loop by yourself (and as best as I can tell, you still can't). I don't believe you can write a simple class by yourself, and see no evidence that you can in the code you posted. How you gonna do virtual polymorphic classes when you don't know what a class is? If you want to play the beginner card, stop asking advanced questions.

Prove me wrong, do the simplest part of the assignment: write me a class that uppercases file data: " another that transforms a file to all uppercase". That does not need anything advanced, so, you can do this, right? Its < 10 lines of code.
Last edited on
Jonnin,

If I were just learning C++ as leisure your recommendation would be valid. Fully learn beginner functions before I ask advanced stuff. However, I am a college student in college. I don't get to pick the assignment. So as the semester has progressed the teacher has given us more advanced items each week. This is why you might be seeing me post even harder things.

It's not like i can ask the teacher to pause the semester while i learn beginner things. I have to try and keep pace with beginner stuff and the advandced stuff.
OOPs?
1
2
//Charles Blackwell CIS 221 M6
#include <iostream> 
its also not like you learned anything taught to date. You are so far behind you are going to fail now. So, your post tells me you can't do the easy part of the assignment, let alone the new complex things, is that what you are saying? That you can't uppercase a string, but expect to grok virtual/poly/inherited stuff?

Its not like most of the people here are self taught either. We all went through college. We know what its like. Many of us, myself included, got behind in a class and failed or dropped it to try again later.
Last edited on
Pages: 12