helllp with loops



I have been fiddling with these damn loops for hours. I am new to c++ but not too programming. My teacher is absolutely worthless. she refuses to help me and explains things very poorly. I have a 100 % on the assignments in the class and do not wish to drop because of this one. I read the sticky about students and believe me I am not one of them . I have been up for like 12 hours messing with this. Here is the problem: I am supposed to read numbers out of a file piano.data and put the results into report.out. The piano file is structured like this



4 // number of categories  

6010 // student number 1 // level of proficiency  

7.0 8.5 7.0 8.5 //scores judge 1  

7.0 7.5 8.0 7.5 //scores judge 2  

7.5 8.0 7.5 8.0 //scores judge 3  

-1 //no more judges  

6012 1  

7.5 7.0 9.5 9.0  

7.0 6.0 10.0 10.0  

7.5 7.5 10.0 9.5  

-1



The problem I have is that I can put the header in, read the student number, display it and use a switch operater to display profieciency. I then have a counter control set up to spit out which judge and then the scores are listed after. Problem being is that it will only display the first list of scores or if i fiddle with it it will just display shit loads of judges with correct scores but eventually the numbers get garbled. It will never  

repeat the student part or the profiency. I believe a sentinal controls one of loops and she wants a for controlled counter statement. then the outer loop searches for end of file i think. I dont know it may be four loops. I am submitting the one that works the best because the ones with more loops spit out all kinds of wierd stuff. here is my code:



```
#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

void SetFormat	(ofstream& fout);
void Header	(ofstream& fout);
double Process	(ifstream& fin, ofstream& fout);
void PrintHigh  (ofstream& fout, double highScore);

int main()
{
	ifstream fin;
	ofstream fout;
	double highScore;
	
	fin.open("Piano.data");
	if (fin.fail())
	{
		cout << "ERROR: Input File\n";
		exit(1);
	}
	
	fout.open("Report.out");
	if (fout.fail())
	{
		cout << "ERROR: Output File\n";
		exit(1);
	}
	
	SetFormat(fout);
	Header(fout);
	highScore = Process(fin, fout);
	
	fin.close();
	fout.close();
	return 0;
}

void SetFormat(ofstream& fout)
{
	fout.setf(ios::fixed);
	fout.setf(ios:: showpoint);
	fout.precision(1);
	return;
}  // end SetFormat

void Header(ofstream& fout)
{
	fout << "     \n\n      Federation of Music Teachers\n";
	fout << " Mardi Gras Piano Invitational Competition\n";
	fout << "	Baton Rouge, Louisiana\n";
	return;
}  // end header

double Process(ifstream& fin, ofstream& fout)
{
	int numCategories;
	int pianoPlayer;
	int level;
	int judgeNumber = 0;
	double scoreType_1, scoreType_2, scoreType_3, scoreType_4;
	double highScore = -999999.99;
	double score;
	double totalScore;
	
	fin >> numCategories;
	while (! fin.eof())
	{
		
		fin >> pianoPlayer;
		fin >> level;
		fout << "Piano Player: ";
		fout.width(1);
		fout << pianoPlayer << "\n";
		fout << "Level: " << level << "\n\n";
		switch(level)
		{
			case 1:		
				fout << " Primary\n";
				break;
			case 2:
				fout << " Intermediate\n";
				break;
			case 3:
				fout << " Advanced Intermediate\n";
				break;
			case 4: 
				fout << " Senior\n";
				break;
			default: 
				cout << " Invalid Code\n";
				break;
		}	
		
		while (scoreType_1 != -1)
		{
			judgeNumber ++;
			fin >> scoreType_1 >> scoreType_2 >> scoreType_3 >> scoreType_4;
			fout << "Judge ";
			
			fout << judgeNumber << "  ";
			score = scoreType_1 + scoreType_2 + scoreType_3 + scoreType_4;
			fout.width(6);
			fout << "Type 1  Type 2  Type 3  Type 4  Score\n";
			fout << scoreType_1 << "   " << scoreType_2 << "   " <<scoreType_3 
			     << "   " << scoreType_4 << score;
			totalScore += score;
			fout << "\n\n";
			fout << "Total: ";
			fout << totalScore;
			
		}
void PrintHigh (ofstream& fout, double highScore);
	{
		fout << "\n\n\n";
		fout << "Highest Score:  ";
		fout.width(5);
		fout << highScore << endl;
		return highScore;
	} //end printhigh	
	}
}
```

If someone could just point me in the right direction with how to go in and out of the loops I could do the rest.
><snip angsty whining> I am supposed to read numbers out  

>of a file piano.data and put the results into report.out.  

How are the results to be formatted? Give us an example run of the program.



>The piano file is structured like this  

Exactly like that? Or are you adding your own commentary? The difference is in how you parse the data, and that's a pretty big difference.
OK I figured it out, I'll put it here to help someone in the future. The key point is the pitch scale change changes the currently PLAYING sound, so it must be used after the play command.


I now have this:



```
soundSamplePlayer.play('success01')
soundSamplePlayer.voice_set_pitch_scale(0,1.2)

```

Basically in `voice_set_pitch_scale(0,1.2)` the first argument (which I have as `0`) is the index of the sound that's playing, so in my case, the first (and only) sound.


The second argument, which I'm testing with `1.2` is the scale change, so 20% higher in this case.


I hope that helps someone in the future. HM ok, another day, another try, but I gotta say: The seemingly endless lessons about numbers and numbers on top of numbers and more numbers are really disencouraging me a lot. It's been a lot of fun up to this point, but I really don't see the point in filling out so much about numbers for the sake of numbers o\_o Could you, like, do a little less of that? not sure i understood. are you having problems with this code?

if yes, i think you’re using the wrong comparison operator (not = but ==). yes i already tried the uff input order like i mentioned in my post.

in the end i just added an additional layer in my neural network to swap from channel-first, to channel-last after the input has been read so this issue can be closed. the score has been removed. Magda, have you found what you need, yet?


I did this many years ago. It is simple… the 2nd time you do it!  

Exit points are simply “interrupts” that IBM supplies. You can attach programs to them, and the programs will automatically run at that point. For setting your AS/400 up to accept FTP logons, for example, the exit point is:  

QIBM\_QTMF\_SVR\_LOGON and the format you wil use is: TCPL0100.


A program inserted there can control WHO can log on, and when.  

To control WHAT they can do, you use another exit point, QIBM\_QTMF\_SERVER\_REQ and use format VLRQ0100.


My notes (from 1999) say I used the IBM TCP manual to get this info, specifically: TCP/IP manual SC41-5420-01 page I-14.


I do not know if it will allow me to post code here, it is long and complex due to the number of variables and some of them being in hex.


Write me (drow@waxie.com) if you would like me to email you my program code.


David Row  

WAXIE Sanitary Supply  

San Diego, CA





This is a link for [Add-ons for Firefox](https://addons.mozilla.org/en-US/firefox/). These are programs written by users or developers that the browser knows how and when to call. The developers of Firefox designed it to allow external programs to be hooked in by users of the browser.


IBM did something similar for a lot of the TCP/IP and other server functions. (And a lot of other things.) When you connect to the FTP server for example, the server checks to see if a program has been registered to process FTP logon requests. The registered program is an ‘exit program’.


Browser add-ons get an entry added to a file someplace within the browser directory structure. In your iSeries, the entry would be added to the Registration Facility. (Not always, but that’s the commonly recognized object for exit points and programs.) Use WRKREGINF to review your registration facility.


To create an exit program, you need to know the parameter list that will be passed to your program and the exit protocol. To find the parameter list, you should start looking at the documentation for the server the exit program will be associated with. The protocol, the meanings of the parms and what to with them, is also there.


A FTP exit program would be structured after documentation within the [File Transfer Protocol exit programs](http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/rzaiq/rzaiqreferenceexit.htm) topic of the Information Center for your release.


Once registered, a server logon exit program (for example) would be called just before the server decides whether or not to accept the logon. Your exit program directly influences that decision by returning an ‘accept or reject’ parameter. It chooses based on examination of the input parms.


The exit program may control who can and cannot logon, where they may logon from, what times of day logons are accepted, or it might accept all logons — its purpose can be simply to write all logons to a log file or to send a message when particular logons happen. Your exit program can do whatever it is programmed to do at that point in the logon process.


It doesn’t have to be a ‘security’ function. It’s whatever you want it to be.


For the FTP server, there are two general exit points. One is just before a logon is accepted. The other is just before each transaction in a session is processed. You can control individual transactions just as you can logons. (FTP client has its own exit points.)


Most other exit programs work on similar principles.


A few issues complicate things.


* An exit program needs enough authority to do whatever it needs to do; it can’t always rely on the authority of the session user.
* An exit program shouldn’t unduly delay transactions; there’s no way to know how often an exit program may be called, so you don’t want it slowing down every single transaction.
* Exit programs may be called by many instances of a server at the same time; it shouldn’t be locking things that are needed by a different instance.
* IBM changes the interfaces at times and the servers themselves can get PTFs; regular, on-going maintenance can be needed — keep the programs direct with little complication.
* There are other issues, but those are enough to consider.


Code a very simple exit program that accepts the parms and returns an ‘Accept’ indication. Don’t have it do anything except maybe send a message to a message queue. That lets you see how the registration facility works and how the parms work. It also gives you a program that you can register and deregister in the future to check whether or not the server is stilling calling your program correctly. (Problems can happen.)


Tom if you do not need the "wave" contents for a further use, just drop out (k) from all its entries.
if you need it for a further use, initialize it as 
wave=zeros(3,numel(t));
before the loop and address it as wave(k,:) within the loop.
commands "stem" are definitely incorrect. if you want to see plots of the dependences on t, they should look something like stem(t,combined) or plot(t,combined), etc. however, the t range in the second version (0,3) is much wider than the one of the first version (0,0.01): consequently, such a graph will show much (hugely) more oscillations--you will probably see nothing but a unifromly painted square.
i do not see any need in the "nold on" and "hold off" commands in the both version. A couple of notes to get started:



> 
> .apply(literal\_eval)
> 
> 
> 


Wouldn't this be better as `map`?



> 
> I then re-create the Dask DF:
> 
> 
> ddf = dd.from\_pandas(ddf\_out, npartitions=nCores)
> 
> 
> 


`ddf_out` was already a dask dataframe, I don't know why you had to do this.



> 
> The columns in result seem to match those in metadir.
> 
> 
> 


The value of `result.columns` is taken from the meta you provided, no computing happens until you ask for it (dask is lazy in most operations). Does the ValueError exception not provide further information?


Here is a full example



```
x = ({'F9_07_PZ_COMP_DIRECT': '0',
  'F9_07_PZ_DIRTRSTKEY_NAME': 'DEBRA MEALY',
  'F9_07_PZ_COMP_OTHER': '0',
  'F9_07_PZ_COMP_RELATED': '0',
  'F9_07_PZ_TITLE': 'CHAIR PERSON',
  'F9_07_PZ_AVE_HOURS_WEEK': '1.00',
  'F9_07_PC_TRUSTEE_INDIVIDUAL': 'X'},
 {'F9_07_PZ_COMP_DIRECT': '0',
  'F9_07_PZ_DIRTRSTKEY_NAME': 'HELEN GORDON',
  'F9_07_PZ_COMP_OTHER': '0',
  'F9_07_PZ_COMP_RELATED': '0',
  'F9_07_PZ_TITLE': 'VICE CHAIR',
  'F9_07_PZ_AVE_HOURS_WEEK': '1.00',
  'F9_07_PC_TRUSTEE_INDIVIDUAL': 'X'})
df = pd.DataFrame({'a': x})
d = dd.from_pandas(df, 1)
meta = pd.DataFrame(columns=['F9_07_PZ_COMP_DIRECT', 
       'F9_07_PZ_DIRTRSTKEY_NAME',
       'F9_07_PZ_COMP_OTHER', 'F9_07_PZ_COMP_RELATED', 'F9_07_PZ_TITLE',
       'F9_07_PZ_AVE_HOURS_WEEK', 'F9_07_PC_TRUSTEE_INDIVIDUAL'], dtype="O")
d.map_partitions(lambda df: df.a.apply(pd.Series), meta=meta).compute()

```

How did I know what `meta` to use? I applied the function to the pandas dataframe - you might use a small piece of the dataframe to do this.


Some additional notes:


* it is an anti-pattern to load the data with pandas, pass to dask workers and then gather the whole result back to a pandas (in memory) dataframe, you are very unlikely to see a speedup this way and may incur a lot of overhead. You are better off loading with something like `dd.read_csv`, and aggregating or writing with dask functions too. Only `compute()` on something that will be small or not return anything (because it involves writing the output). The official examples do not use from\_pandas.
* string and dict processing are python methods, and so hold the interpreter lock (GIL) of any python function: threads will not actually run in parallel. To get parallelism, you need to run in processes, which is most easily achieved using <https://docs.dask.org/en/latest/setup/single-distributed.html>
* the distributed scheduler also gives you access to the dashboard, which has a lot of useful information to diagnose how your system is running. You can also configure a lot about its behaviour, in case you have firewall rules you need to obey. class intervals
frequency
(fi)
xi
di = xi - a
fi di


0 - 20
17
10
-40
-680


20 - 40
28
30
-20
-560


40 - 60
32
50 = a
0
0


60 - 80
p
70
20
20p


80 - 100
19
90
40
760


total
Î£
fi = 96 + p


Î£ fi di = 20p -
480


![](https://s3mn%20mnimgs%20com/img/shared/discuss_editlive/5130830/2013_07_08_13_01_36/mathmlequation8813644107607516415%20png) Something like the following code should do the trick, provided you complete it (just plan 'A' is covered') and make it robust.  

  


```
#include<stdio.h>

int get\_description(const char type\_plan[], const char ** description, const char ** claim\_limit )
{
  int result = 0; // 0 is 'success' , non-zero is 'failure' 

  switch (type\_plan[0])
  {
  case 'A':
    *description = "Room Charges 150/day\nIntensive Care Unit (ICU) Charges 300/day\nHospital Supplies and Services : As charged. Subject to approval by EZMediLife. Surgical Fees\n";
    switch(type\_plan[1])
    {
    case '1':
      *claim\_limit = "Annual Claim Limit 100.000\n";
      break;

    case '2':
      *claim\_limit = "Lifetime Claim Limit 500000\n";
      break;

    default:
      result = -1;
      break;
    }

    break;
  case 'B':
    //...

  case 'C':
    //...

  default:
    result = -1;
    break;
  }

 return result;

}


int main()
{
  const char * plane[]  = { "A1", "K3", "A2" }; -- test planes

  for ( size\_t n=0; n<sizeof(plane) / sizeof(plane[0]); ++n)
  {
    const char * description, * claim\_limit;
    if ( get\_description( plane[n], &description, &claim\_limit) == 0)
    {
      printf("plane %s: %s%s", plane[n], claim\_limit, description);
    }
    else
    {
      printf("unknown plane %s\n", plane[n]);
    }
    printf("\n");
  }
  return 0;
}
```