I am working on an exercise given in class. I have managed to do most of it but I a a bit stuck on the permutation part. Here is what is required of me:

Subject: Transformers

An ideal electrical transformer has an input voltage and current, Vin, Iin and an output
voltage and current, Vout, Iout. The relationship between inputs and outputs is
Vout =nVin, Iout =Iin /n Where n is the transformer’s turns ratio.

If two transformers are cascaded then they “ideally” behave as an equivalent transformer with n=n1 X n2

However, in practice each transformer has maximum values of Iin and Iout, above which
the transformer burns out.

An input file named cascade.dat in the following format is to be read
n1 Iin1max Iout1max

n2 Iin3max Iout2max

n3 Iin3max Iout3max

… etc

Each triplet of floats specifies a transformer. These transformers are to be cascaded, not
necessarily in the order of the file.

The number of transformers is unknown until the file is read. Note that the turns ratio of the single transformer equivalent to the cascade of all transformers doesn’t depend upon the cascading order.

Write a program to determine the maximum input current that can be applied to the
cascade without any transformer burning out if the transformer ordering can be arbitrary.

Note. This program is not required to be very efficient. A simple consideration of all
possible orderings of the transformers is sufficient.

Although not really necessary here, good OOP principles must be adopted – who knows
where this code may be reused.

To deal with the more general case you will need to be able to “loop through” all possible
permutations of the transformer order. How does one generate all possible orderings? –
not covered in any modules I expect. Well there are simple algorithms “out there” and in
this world of the internet, you need to get used to finding these sorts of “useful
algorithms”.

and here is the code I have so far:

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

//define the transformer as a class
class transformer
{
public:
float iout; //output current in amps
float n;  //transformer's turns ratio
float iinmax; //max input current before the transformer burns out in amps
float ioutmax; //max output current before the transformer burns out in amps
//declare constructor
transformer();
//delcare destructor
~transformer();
};
//define constructor
transformer::transformer()
{

iout = 0.;
n = 0.;
iinmax = 0.;
ioutmax = 0.;
}

//main program
void main()
{
int nu = 0; //variable to hold the number of lines and thus transformers
char buf[256]; //buffer of 256 charecters used to count the number of lines
transformer *p; //pointer of type tranformer
float turns_ratio = 1.; //turns ratio of cascade
float ioutcasc, iincasc;

ifstream infile; //input file stream

//check if file was opened successfully
if (infile.fail())
{
cout<<"Failed to open file"<<endl;
}
else
//  cout<<"File opened successfully\n";
//read the contents of the file until the end
while (!infile.eof())
{

infile.getline(buf,256);
nu ++;
}
//close the file
infile.close();

//The number of transformers is 1- nu
nu = nu-1;

//display the number of transformers
cout<<"There are "<<nu<<" transformers\n";

//create array of tranformers
p = new transformer[nu];
//open the file again to read the values

//check if file was opened successfully
if (infile.fail())
{
cout<<"Failed to open file"<<endl;
}
else
//  cout<<"File opened successfully\n";

//assign values from the file into the corresponding tranformers
for(int i=0;i<nu;i++)
{
infile>>p[i].n>>p[i].iinmax>>p[i].ioutmax;
}
//close file
infile.close();
//calculate and display the turns ratio of the cascade
for(int k=0;k<nu;k++)
{
turns_ratio *= p[k].n;
}
cout<<"The turns ratio of the cascade is "<<turns_ratio<<"\n";

}``````

Now, I tried very hard to find a some kind of algorithm that I can use for permuting the sequence of cascades, but I can never understand how they work inorder to modify them to my design.

Any suggestions on how the calculation and permutation can be carried out?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.