C++

Can anyone help me with my c++ program? Its a program I have to write using structs and arrays and i'm stuck. If anyone can help can you post back and I'll show you what i've got and maybe you can tell me why its not working correctly.
Thanks

I can try. I have not done much outside of Visual Basic. But maybe I can figure out your problem.


My assignment is to initialize an array of structs using the data from an input file. To get the input file the user must input the name of the file.Theres more i need to add but i cant get this to work so i havent even tried the other stuff.
Well this is what ive got so far...

#include <iostream>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

const int ARRAY_SIZE = 40;

struct studentType
{
string firstName;
int id;
int testScore;
};

void getData(ifstream& inData, studentType sList[], int& listSize);
void printList(const studentType sList[], int listSize) ;

int main()
{
int student_count;
studentType studentList [ARRAY_SIZE];

ifstream inData;

char inputFile[40];

cout << "Please enter the name of the input file you would like to use"
<< " and press enter"
<< endl;
cin >> inputFile;

inData.open(inputFile);

if (!inData)
{
cout << "The input file does not exist."
<< endl;

}

getData(inData, studentList, student_count);
printList(studentList, student_count);

system ("pause");
return 0;
}

void getData(ifstream& inFile, studentType sList[], int& listSize)
{
int i = 0;
cout << "getData\n";

if ( !inFile)
cout << " no File\n ";


inFile >> sList[0].firstName >> sList[0].id
>> sList[0].testScore ;

while (inFile)
{
i++;
inFile >> sList[0].firstName >> sList[0].id
>> sList[0].testScore ;
}
listSize = i ;
cout << "listSize = " << listSize <<endl <<endl <<endl;
}

void printList(const studentType sList[], int listSize)
{

  1. 👍 0
  2. 👎 0
  3. 👁 82

Respond to this Question

First Name

Your Response

Similar Questions

  1. c programming

    a student designed a program to accept the age of an employee and then compute the employees retirement year and display the same in a statement on the screen required. a) write out the pseudo-code for the program above b) write

    asked by riley on October 14, 2014
  2. Programming

    Write a program that would calculate and display the results for the multiplication table for values ranging from 1 to 100. Your program should print the output for each step and output a new line after 10 items. Provide your

    asked by Larisha on September 23, 2012
  3. Programming

    Write a pseudocode program that asks the user for an integer between 1 and 12. The program is to calculate the times table for that number. So for example, if the user enters a 2, then the program has to calculate 2x1 and display

    asked by Darlene on August 17, 2011
  4. HSM/270

    Last few weeks of class and struggling to keep up to graduate, can somebody help me if they have done this before, also i used the PEACE Program for my assignments in this Grant Proposal and Writing class. Thanks Identify where

    asked by Kelly on September 8, 2012
  5. C++

    // Program: name of program // Author: your name // Date Written: date you began writing the program /* Abstract: Brief description of the program */ Include in-line comments in the body of your program. You can convert

    asked by Frank on September 23, 2016
  6. MATH

    WRITE A SIMPLE BUT A COMPLETE FORTRAN PROGRAM TO COMPUTE THE AVERAGE OF SIX NUMBERS AND DISPLAY THE NUMBERS, SUM AND AVVERAGE. THE PROGRAM SHOULD TERMINATE WHEN ZERO IS ENTERED AS A NUMBER. THE PROGRAM SHOULD BE EDUCATIVE

    asked by EDWIN on June 15, 2011
  7. statistics

    the average number of years a person takes to complete a graduate degree program is 3. the standard deviation is 4 months. Assume the variable is normally distributed. If an individual enrolls in the program, find the probability

    asked by Michelle on May 16, 2011
  8. English

    1. I watch documentaries when I feel down. (What is the meaning of 'feel down'?) 2. This is a news program. This is an animation program. This is a game show program. This is a soap opera. This is a comedy program. (Are the

    asked by John on March 19, 2009
  9. Early Child Ed.

    Which one would be the best answer? Would (A) be the best answer? The opposite of a traditional language program might be which: A. developmentally appropriate practice B. conventional program C. back-to-basics program D.

    asked by Lydia on September 5, 2007
  10. Web Design and Development

    Explain how an affiliate program works as both an advertising program and a revenue generation program; give two real-world affiliate program examples.

    asked by Pete Watson on February 2, 2013
  11. Programming in c++

    Draw a flow-chart and Write a program that asks the user to enter students grades. The program should stop reading when the use enters ‘*’. In addition, your program should print the number of students got each grade. The

    asked by alhan on April 15, 2013

More Similar Questions