CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Apr 2017
    Posts
    2

    Lightbulb A few questions about my project

    Hello all. I am new to C++ programming and using Microsoft Visual Studio as my IDE. My first problem is I am unable to find the "Win32" template under C++ in the Microsoft Visual Studio 2017 Community Edition that is required of me to complete this project. With that being said, I went ahead and selected a "Empty Project" template to just begin coding so I have at least something. My second question is I am having trouble running the code from the command line. I am unsure if it is a logic error somewhere or if I need to get the Win32 template in order for this particular project to work.

    The project requires me to read in student ID numbers and then a series of test scores that will be averaged after all of the data has been read in. I will display my code below in order to see if I am going about this correctly and how I can get the Win32 template downloaded so I can actually run my code.

    Code:
    #include <fstream>
    #include <iostream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    ifstream in ("data1.txt");
    ofstream out;
    
     
    const int rows = 50;
    const int cols = 5;
    
    
    
    void read_input(ifstream &in, float IDs[], float scores[][cols], int &num_students) 
    {
    
    	float studentID;
    	float grade1, grade2, grade3, grade4;
    
    	while (true) {
    		in >> studentID;
    		if (studentID < 0) {return;}
    		in >> grade1;
    		in >> grade2;
    		in >> grade3;
    		in >> grade4;
    		IDs[num_students] = studentID;
    		scores[num_students][0] = grade1;
    		scores[num_students][1] = grade2;
    		scores[num_students][2] = grade3;
    		scores[num_students][3] = grade4;
    		num_students++;
    	}
    }
    
    void bubble_sort(int A[rows][cols], int size, int keyindex)
    {
    	int i, j;
    	int buff1, buff2, buff3;
    	for (i = 0; i < (size - 1); i++)
    		for (j = 0; j < (size - i - 1); j++)
    			if (A[j][keyindex] <  A[j + 1][keyindex])
    			{
    				buff1 = A[j][0];
    				buff2 = A[j][1];
    				buff3 = A[j][2];
    				A[j][0] = A[j + 1][0];
    				A[j][1] = A[j + 1][1];
    				A[j][2] = A[j + 1][2];
    				A[j + 1][0] = buff1;
    				A[j + 1][1] = buff2;
    				A[j + 1][2] = buff3;
    			}
    }
    
    void print_studentInfo(ofstream &outfile, float IDs[], float scores [][5], int &num_students) 
    { 
    	out << "Student ID  Test 1  Test 2  Test 3  Test 4" << endl;  
    	out << "----------  ------  ------  ------  ------" << endl; 
    	for (int i = 0; i  <  num_students; i++) 
    	{ 
    		outfile << setw(7) << IDs [i] << "   " << setw(7) << scores[i][1] << "   " << setw(7) << scores[i][2] << "   " << setw(7) << scores[i][3] << "   " << setw(7) << scores[i][4] << "   " << setw(7) << scores[i][5] << endl;
    	}
    		out << endl << endl << endl; 
    }
    
    int main()
    {
    	float IDs[50];
    	float scores[rows][cols];
    	int num_students = 0;
    	read_input(in, IDs, scores, num_students);
    	print_studentInfo(out, IDs, scores, num_students);
    	//bubble_sort(student_records, num_students, 1);
    	return 0;
    
    }
    I am just trying to see if this code will actually read in the numbers and put them into the array and then display them.
    Last edited by 2kaud; September 24th, 2017 at 04:59 AM. Reason: Added code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured