Bedienung Xcode/ Kein Output , woran liegts?



  • Ich hätte ne Anfängerfrage.
    Soll einen gegebenen Code abändern, kämpfe dabei im Moment aber noch mehr mit der Bedienung von Xcode als dem Code selbst.
    Wenn ich folgenden Code kompiliere und ausführe bekomme ich im Terminal keinen Output. Liegt das daran, dass er die Quelldaten nicht richtig einliest, oder fehlt einfach noch ein Stück im Code? Die Quelldaten befinden sich in der Datei data_a.

    #include <iostream>
    
    using namespace std;
    
    const int MAX_NR_PROTEINS = 100; // can be more than actual number of proteins 
    const int NR_DESCRIPTORS  = 5;   // should be the same as the actual number of columns
    const int MAX_NAME_LENGTH = 10;  // can be more than the actual maximum name length
    
    void read_input(char names[MAX_NR_PROTEINS][MAX_NAME_LENGTH], 
    				float table[MAX_NR_PROTEINS][NR_DESCRIPTORS], 
    				int &nr_objects);
    
    void sort_by_column(float table[MAX_NR_PROTEINS][NR_DESCRIPTORS], 
    					int nr_objects, int column);
    
    void write_output(char names[MAX_NR_PROTEINS][MAX_NAME_LENGTH], 
    				  float table[MAX_NR_PROTEINS][NR_DESCRIPTORS], 
    				  int nr_objects);
    
    int main()
    {
    	char  protein[MAX_NR_PROTEINS][MAX_NAME_LENGTH];
    	float descriptors[MAX_NR_PROTEINS][NR_DESCRIPTORS];
    	int nr_proteins;
    
    	read_input(protein, descriptors, nr_proteins);
    
    	sort_by_column(descriptors, nr_proteins, 1); // sort the descriptors 
    	// by RMSD, i.e., according to the second column of numbers. Since 
    	//   indices start with zero, we have to pass a "1" for the second column.
    
    	write_output(protein, descriptors, nr_proteins);
    
    	return (0);
    }
    
    void read_input(char names[MAX_NR_PROTEINS][MAX_NAME_LENGTH], 
    				float table[MAX_NR_PROTEINS][NR_DESCRIPTORS], 
    				int &nr_objects)  
    // the last variable needs to be passed by reference so that its value 
    //   can be modified by the function. Arrays are passed by reference 
    //   anyway. 
    {
    	int j;
    
    	nr_objects = 0;
    
    	for (nr_objects = 0; nr_objects < MAX_NR_PROTEINS; nr_objects++) {
    		if ((cin >> names[nr_objects]) == 0) {
    			break; // stop if there's no more input
    		}
    		for (j = 0; j < NR_DESCRIPTORS; j++) {
    			cin >> table[nr_objects][j];
    		}
    	}
    
    }
    
    void sort_by_column(float table[MAX_NR_PROTEINS][NR_DESCRIPTORS], 
    					int nr_objects, int column)
    {
    	// perform an insertion sort on "nr_objects" rows of table "table" 
    	// with the sort key given by column "column" 
    
    	int i, j, k;
    	float tmp_row[NR_DESCRIPTORS];
    
    	for (j = 1; j < nr_objects; j++){         // big loop over all rows
    		//     in table
    		for (k = 0; k < NR_DESCRIPTORS; k++) {  // store a temporary copy of 
    			tmp_row[k] = table[j][k];             //     the current row
    		}                                      
    		i = j - 1;
    		while ((i >= 0) && (table[i][column] > tmp_row[column])) {  
    			for (k = 0; k < NR_DESCRIPTORS; k++) {// move all the rows which 
    				table[i + 1][k] = table[i][k];      //     have a bigger element in 
    			}                                     //     the desired column downwards
    			i--;
    		}
    		for (k = 0; k < NR_DESCRIPTORS; k++) {  // insert the temporary copy of 
    			table[i + 1][k] = tmp_row[k];         //     the current row in its 
    		}                                       //     proper place
    	}
    }
    
    void write_output(char names[MAX_NR_PROTEINS][MAX_NAME_LENGTH], 
    				  float table[MAX_NR_PROTEINS][NR_DESCRIPTORS], 
    				  int nr_objects)
    {
    	int i, j;
    
    	cout << "\n\n PDB proteins, ordered by RMSD from 2OCJ:A\n\n\n";
    
    	cout.setf(ios::fixed);
    	cout.setf(ios::right);
    
    	for (i = 0; i < nr_objects; i++) {
    		cout << names[i] << " ";
    		for (j = 0; j < NR_DESCRIPTORS; j++) {
    			cout.precision(1); // these are the inner loop because they need to 
    			cout.width(7);     // be reset after each writing to the stream. 
    			cout << table[i][j];
    		}
    		cout << "\n";
    	}
    }
    


  • Und an welcher Stelle in deinem Code kommt data_a vor?
    Zusatzfrage: was macht cin?


Log in to reply