Thread: initializes all components of failing to false

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    73

    initializes all components of failing to false

    I have a three part assignement but if I can figure out this first one I will be good with the other two. I am not quite sure what they want me to do, do I need to make a program that tells if they 100 students grades inputed are failing or passing? Do I enter 100 test scores, or do I make a loop to add one point to each test score? I am confused!

    Here is the problem:

    Use the following declarations in Exercise 1-7. You may declare any other variables that you need.

    Code:
    cont int NUM_STUDS = 100;
    
    bool failing [NUM_STUDS];
    bool passing [NUM_STUDS];
    int grade;
    int score[NUM_STUDS];
    Write a C++ function that initializes all components of failing to false. The failing array is a parameter.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    we need more clarification on what the instructions are.

    Are you given a file with scores that you have to decide if they are passing or failing? or do you have to enter certain scores?

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    73
    I think that is my problem, we are not told anything else. I tried to email the profesor but he is not responding.....

    Bryan

  4. #4
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    Write a C++ function that initializes all components of failing to false. The failing array is a parameter.
    Well, you must write a function, so start with that. It must take the failing array as an argument, and the failing array is an array of bools, so that should give you a hint as to what the type of the parameter is. You also must figure out if this function must return anything.

    Then for the actual body of the function, what is it supposed to do? Its supposed to initialize all components of an array to false. That means it must do something for each entry in the array. Smells like a loop to me.

    Does that help?

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    failing is an array of type bool so the elements of the array can only have one of two values: true or false. Your directions are to write a function that initializes all the elements of the array with false. That means you are supposed to assign the value false to each element of the array. Simple enough.

    "The failing array is a parameter." That statement is redundant, and it means you are supposed to send the failing array to the function so that it can set all the elements of the array to false.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    wow, I completely missed the instructions under the code.

    Do what the above two have posted, and if you still need help, post some code and we'll help.

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    73
    here is wha tI have so far...am I on the right track?

    Code:
    #include <iostream>
    
    using namspace.std;
    
    Void Initialize(/* out */ bool Failling[])
    
    int main()
    
    {
    Int Index;
    int NUM_STUDS[] = {35, 78, 90, 100, 65};
    
    for(index=0; index < NUM_STUDS; index++)
    failing[index]=false
    }

  8. #8
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    as said in the instructions, you need to use the code in your first post.

    check your using namespace std; line. also, the for loop should not be in main, but in the function.

    I don't think you can do:

    int NUM_STUDS[] with the const int NUM_STUDS = 100; line. that loop condition would be correct if NUM_STUDS[] array weren't there. you shouldn't need that array, at least not for the function of setting the elements of the failing array to false.

    you also have some syntax errors.

    Code:
    #include <iostream>
    using namespace std;
    
    const int NUM_STUDS = 100;
    
    void Initialize(bool Failing[]);
    
    int main()
    {
      bool failing [NUM_STUDS];
      bool passing [NUM_STUDS];
      int grade;
      int score[NUM_STUDS];
    
      //pass the failing array here to the fxn.
      //and whatever else the instructions say is needed
    
      return 0;
    }
    
    void Initialize(bool Failing[])
    {
      //fill this in with the code that is supposed to set
      //the failing array elements to false.
    }
    This should help you get started some.

  9. #9
    Registered User
    Join Date
    Jun 2003
    Posts
    73
    thanks..I'm gong to work on it now..

    Bryan

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    for(index=0; index < NUM_STUDS; index++)

    NUM_STUDS is an array and the address of the array is stored in the array name. If you want to access one of the elements of the array, you need to reference it like this:

    NUM_STUDS[0] ---(which happens to be 35)

    or

    NUM_STUDS[1] ---(which happens to be 78)

    not

    NUM_STUDS

  11. #11
    Registered User
    Join Date
    Jun 2003
    Posts
    73
    if they want me to initialize all compoenets of failing to false, what exactly am I trying to do? I dont specify in this program what is passing or failling, that is a totally differenet program, and I kow if I did I would put >=60 ..stuff like that, but what exactly am I trying to find? that is what I dont understand...Also, would i need to add in the passing, grade, score since I am not really doing anything with those?


    Code:
    #include <iostream>
    
    using namespace std;
    
    const int NUM_STUDS = 100;
    
    void Initialize(bool Failing[]);
    
    int main()
    {
      bool failing [NUM_STUDS];
      bool passing [NUM_STUDS];
      int grade;
      int score[NUM_STUDS];
    
      //I'm still confused at this part
    
      return 0;
    }
    
    void Initialize(bool Failing[])
    {
    	int index;
    
      for(index=0; index<NUM_STUDS; index++)
    	  Failing[index]=false;
    
    }
    Last edited by romeoz; 08-01-2003 at 03:49 PM.

  12. #12
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    the Initialize fxn looks good. Now just call the function passing the failing array as the parameter. that should complete that part of the program.

    As for the other declarations of passing, grade, and score; the instructions say to use those declarations for exercises 1 - 7. I take it that the problem involving setting the elements of the failing array to false is part of exercises 1 - 7. do as you see fit.

  13. #13
    Registered User
    Join Date
    Jun 2003
    Posts
    73
    I'm getting an error with my 2nd void statement: 3 in all

    warning C4518: 'void ' : storage-class or type specifier(s) unexpected here; ignored
    error C2146: syntax error : missing ';' before identifier 'SetFailing'
    fatal error C1004: unexpected end of file found

    I made a InData file with 100 test scores so it can open it up and ge all the test scores to look at but something is still wrong...I hope I am not to far off..

    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    const int NUM_STUDS = 100;
    ifstream InData;
    
    void Initialize(bool failing[])
    void SetFailing(bool failing[],const int score[])
    void SetPassing(bool passing[],const int score[])
    
    int main()
    {
    	bool failing [NUM_STUDS];
    	bool passing [NUM_STUDS];
    	int grade;
    	int score [NUM_STUDS};
    
    	InData.open("InData.txt");
    		if (!InData.fail())
    	InData >> grade;
    else
       cout<<"Error opening file";
    
    	cout << "The number of failing is:" << failing << endl;
    	cout << "The number of passing is:" << passing << endl;
    
    	return 0;
    	}
    
    
    void Initialize(bool failing[])
    {
    	int index;
    
    	for(index=0; index<NUM_STUDS; index++)
    		failing[index]=false
    
    }
    
    void SetFailing(bool failing[],const int score[])
    {
    	int index;
    
    	for(index=0; index<NUM_STUDS; index++)
    		if (score[index]<60)
    			failing[index]=true
    }
    
    void SetPassing(bool passing[],const int score[])
    {
    	int index;
    
    	for(index=0; index<NUM_STUDS; index++)
    		if (score[index]>=60)
    			passing[index]=true
    	
    }
    Last edited by romeoz; 08-01-2003 at 08:18 PM.

  14. #14
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    const int NUM_STUDS = 100;
    ifstream InData;
    
    void Initialize(bool failing[])
    void SetFailing(bool failing[],const int score[])
    void SetPassing(bool passing[],const int score[])
    
    int main()
    {
    	bool failing [NUM_STUDS];
    	bool passing [NUM_STUDS];
    	int grade;
    	int score [NUM_STUDS};
    
    InData.open("InData.txt");
    if (!InData.fail())
       InData >> grade;
    else
       cout<<"Error opening file";
    
     return 0;
    }
    
    
    void Initialize(bool failing[])
    {
    	//int index;
    
    	for(int index=0; index<NUM_STUDS; index++)
    		failing[index]=false;
    
    }
    
    void SetFailing(bool failing[],const int score[])
    {
    	//int index;
    
    	for(int index=0; index<NUM_STUDS; index++)
    		if (score[index]<60)
    			failing[index]=true;
    }
    
    void SetPassing(bool passing[],const int score[])
    {
    	int index;
    
    	for(index=0; index<NUM_STUDS; index++)
    		if (score[index]>=60)
    			passing[index]=true;
    }
    
    //um is this supposed to be in main?
    {
    	cout << "The number of failing is:" << failing << endl;
    	cout << "The number of passing is:" << passing << endl;
    
    	return 0;
    }
    I just though you might want to check to see if the file exists or if it is actually being opened (I think fail() is the correct function). Also you missed a semicolon and you have some stray code...not sure if that fixes everything though
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  15. #15
    Registered User
    Join Date
    Jun 2003
    Posts
    73
    I modified the code above..thanks for the help. Istill get these erros.:

    'void' : storage-class or type specifier(s) unexpected here; ignored
    error C2146: syntax error : missing ';' before identifier 'SetFailing'
    : fatal error C1004: unexpected end of file found
    Last edited by romeoz; 08-01-2003 at 08:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. the chess project
    By Hussain Hani in forum Projects and Job Recruitment
    Replies: 8
    Last Post: 05-28-2007, 02:33 AM
  2. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM