?
Solved

Algorithm

Posted on 2000-02-06
18
Medium Priority
?
366 Views
Last Modified: 2011-10-03
I want to develop an algorithm that solves the Y2k problem by changing all the y's to k's in a documents.(can be assumed that a document is merely and array of characters) What are good especifications for it?
0
Comment
Question by:q_low
  • 8
  • 5
  • 4
  • +1
18 Comments
 
LVL 1

Expert Comment

by:snifong
ID: 2494862

#include <fstream.h>
#include <iostream.h>

void main()
{
char c;
ifstream Infile("input.txt", ios::in);
ofstream Outfile("output.txt", ios::out);
   while((c=Infile.get()) != EOF) {
      if((c=='y')||(c=='Y'));
            Outfile.put('k');
   }
}
0
 
LVL 1

Expert Comment

by:snifong
ID: 2494867
Sorry.  This is a little different.  It writes to another file.
#include <fstream.h>
#include <iostream.h>

void main()
{
char c;
ifstream Infile("input.txt", ios::in);
ofstream Outfile("output.txt", ios::out);
   while((c=Infile.get()) != EOF) {
      if((c=='y')||(c=='Y'));
         Outfile.put('k');
      else
         Ouputfile.put(c);
   }
}
0
 

Author Comment

by:q_low
ID: 2494887
What about specifications?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 22

Expert Comment

by:nietod
ID: 2495107
We cannot provide answers to school assignments.  That is grounds for removal from this site.  (for both you and the experts involved.)  We can provide only limitied help in accademic assignments.    We can answer specific (direct) questions, like you might ask your teacher.  We can review your work and post suggestions, again, like your teacher might do.

Do you have specific questions?
Do you have any work on this (incomplete even) that we can review?
0
 
LVL 1

Expert Comment

by:snifong
ID: 2495243
Post a few of the ones that you think should be there and then let us look at them and help you out where you are stuck.
0
 

Author Comment

by:q_low
ID: 2495865
nietod...this is no school assigment if you are learning this by yourself. So i make it clear it ain't an assigment. As far as code is concern, I'm working on it again to post it so you can give me a better help, had a pc crashed and had to get a new disk so i don't have my program.Thanx
0
 

Author Comment

by:q_low
ID: 2495875
What I meant by specifications in the question was meant to be like this:
if array has to have at least one element, etc....
0
 

Author Comment

by:q_low
ID: 2497851
Not what i asked for. I asked by specifications not a program
0
 
LVL 22

Expert Comment

by:nietod
ID: 2497875
What do you mean by specifications?  And why do you need them?
0
 

Author Comment

by:q_low
ID: 2498167
Well to have some idea what i got to do in the problem.I feel it is too ambiguous. So I am asking you what do I have to take in consideration to make the program.
0
 
LVL 1

Expert Comment

by:snifong
ID: 2498229
What do you have so far?
0
 

Expert Comment

by:SISU
ID: 2499578
Hi,
  Use the followinf code

void main()
{
char c;
fstream Outfile("output.txt",ios::in|ios::out);
   while((c=Outfile.get()) != EOF)
   {
      if((c=='y')||(c=='Y'))
      {  outfile.seekp(-sizeof(c),ios::cur);
         Outfile.put('k');
      }
    }
}
Hope this will help U

Sisu
0
 
LVL 22

Expert Comment

by:nietod
ID: 2499819
SISU, have you read the question history?  You can't answer a question unless you've read it!
0
 

Author Comment

by:q_low
ID: 2499942
I'm not looking for a program.
0
 

Author Comment

by:q_low
ID: 2499946
Will these be good specifications?
1. array >0
2. at least there should be one y in the array
3.return array with y's changed with k's
0
 
LVL 22

Accepted Solution

by:
nietod earned 90 total points
ID: 2500057
Number 3 certainly is, that is the point of the program.

Number 1 is debatable.  A 0 length array is, well, not really an array.  Dependign on your algorithm the array length won't matter much.  It depends on other requirements you develope, like up to how long will the file be?  Can it be any length or will there be a maximum length?

Number 2, is debatable again.  Why would you need that restriction? Its like writting a spelling checker and saying it can be used on a document only if there is at least one spelling mistake.  Well the user might not even know if there is a spelling mistake, so how will they know if they can use it?  Ask yourself, is there a good reason for having this restriction?  Maybe there is, I don't see it though..

Things to consider:
Does the program handle files of any length?
Files with any name?
Does it handle both upper and lowercase letters?
Do the files have to be of a certain type?  (Like text files, could they be EXEs)?
0
 

Author Comment

by:q_low
ID: 2517067
k thanx
how do I get points or award pints>?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2517098
You need to pick the expert that you think helped the most and either ask them to submit an answer or you can accept one of their comments as an answer (this option appears at the top of the comment box).
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question