Structured Array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • godsent
    New Member
    • Aug 2006
    • 33

    Structured Array

    hi
    my question goes like this


    Write a program that can store stidents' marks into a structured array.the array will store the test marks for 10 students.Each student is required to take 3 tests..

    Student No Test1 Test2 Test3
    1 50 60 70
    2 80 30 70
    3 100 50 40
    .
    .
    .
    .
    .
    .

    this goes like this for 10 students


    the program should be able to ;
    (1) Print out all data
    (2)Print out data for test 2
    (3)Print out the address for array 3
    (4)Print out the address for test3

    thanks
  • godsent
    New Member
    • Aug 2006
    • 33

    #2
    Urgent
    plxz

    Comment

    • godsent
      New Member
      • Aug 2006
      • 33

      #3
      urgent...plz reply

      Comment

      • risby
        New Member
        • Sep 2006
        • 30

        #4
        Originally posted by godsent
        urgent...plz reply
        You haven't asked a question.

        Comment

        • godsent
          New Member
          • Aug 2006
          • 33

          #5
          Originally posted by risby
          You haven't asked a question.
          i got to write this program in C++..

          the questions are :
          1. Print out all the data
          2.Print out the data for test 2
          3.Print out the address for the array
          4.Print out the address for test 3

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Originally posted by godsent
            i got to write this program in C++..

            the questions are :
            1. Print out all the data
            2.Print out the data for test 2
            3.Print out the address for the array
            4.Print out the address for test 3
            These are not questions they are statements, and statements 2 and 4 are not complete and make no sense.

            Please ask actual questions, we are not going to guess at what you wish to know and we are not going to write your code for you.


            I suggest you start by working out what structure (or may be class since it's C++) you will use, and how you will get the data into the program.

            Once you are there you can decided how to interface with the user and how you will print the data.

            Comment

            • godsent
              New Member
              • Aug 2006
              • 33

              #7
              Originally posted by Banfa
              These are not questions they are statements, and statements 2 and 4 are not complete and make no sense.

              Please ask actual questions, we are not going to guess at what you wish to know and we are not going to write your code for you.


              I suggest you start by working out what structure (or may be class since it's C++) you will use, and how you will get the data into the program.

              Once you are there you can decided how to interface with the user and how you will print the data.
              heya thankx
              IT WORKED....

              Comment

              • godsent
                New Member
                • Aug 2006
                • 33

                #8
                helo
                i've done this in a one dimensional array..all are working perfectly.... I wana know if i can do it in other way...for eg, using files or 2 dimensional array...

                Comment

                • Banfa
                  Recognized Expert Expert
                  • Feb 2006
                  • 9067

                  #9
                  Probably but it's hard to tell without seeing what you have already done

                  Comment

                  • godsent
                    New Member
                    • Aug 2006
                    • 33

                    #10
                    Originally posted by Banfa
                    Probably but it's hard to tell without seeing what you have already done

                    Code:
                     #include<iostream.h> 
                     
                     
                    void main()
                    {
                     
                    	int stud_id [10]={1,2,3,4,5,6,7,8,9,10}; 
                     
                     
                    	int test1[10]={50,80,100,90,70,70,30,60,50,100}; 
                     
                     
                    	int test2[10]={60,30,50,80,70,80,20,70,60,100};
                     
                     
                    	int test3[10]={70,70,40,90,70,80,50,50,70,90};
                     
                     
                    	int * mypointer; 
                     
                     
                    	mypointer=stud_id;
                     
                    	mypointer=test1;
                     
                    	mypointer=test2;
                     
                    	mypointer=test3;
                     
                     
                    //	cout<<"The address of array student id 1 is "<<&stud_id[0]<<endl;
                    //	cout<<"The address of array student id 2 is "<<&stud_id[1]<<endl;
                     
                     
                    cout<<"Student ID"<<"\t"<<"Test 1"<<"\t"<<"Test 2"<<"\t"<<"Test 3"<<endl;
                     
                    for (int i=0;i<10;i++)
                    	{
                     
                    		cout<<stud_id[i]<<"\t"<<"\t"<<test1[i]<<"\t"<<test2[i]<<"\t"<<test3[i]<<endl;
                     
                    	}
                     
                    cout<<endl;
                    cout<<endl;
                     
                     
                    cout<<"Student ID for test 2"<<"\t"<<"Test 2"<<endl;
                     
                    for (int t=0;t<10;t++)
                    	{
                     
                    		cout<<stud_id[t]<<"\t"<<"\t"<<test2[t]<<endl;
                     
                    	}
                     
                    cout<<"The address for test 3 is "<<&test3<<endl;
                     
                    }
                     
                    its as simple as that
                    ..
                    i want 2 use 2 arrays,one for "test" and one for "student Id"..
                    please guide me on how to go about

                    thanks
                    Last edited by Niheel; Oct 5 '06, 03:53 PM.

                    Comment

                    • Banfa
                      Recognized Expert Expert
                      • Feb 2006
                      • 9067

                      #11
                      Originally posted by godsent
                      #include<iostre am.h>
                      i want 2 use 2 arrays,one for "test" and one for "student Id"..
                      please guide me on how to go about
                      Obviously the array stud_id doesn't change, you can change the test array to something like

                      Code:
                      int test[3][10]={
                          {50,80,100,90,70,70,30,60,50,100},
                          {60,30,50,80,70,80,20,70,60,100},
                          {70,70,40,90,70,80,50,50,70,90}
                        };
                      
                      this
                      
                      	cout<<stud_id[t]<<"\t"<<"\t"<<test2[t]<<endl;
                      
                      becomes
                      
                      	cout<<stud_id[t]<<"\t"<<"\t"<<test[1][t]<<endl;
                      Personally I would be inclined to use a array of structures

                      Code:
                      typedef struct student {
                          int stud_id;
                          int test_results[3];
                      } STUDENT;
                      
                      STUDENT students[10] = {
                          {1, {50, 60, 70}},
                          {2, {80, 30, 70}},
                          {3, {100,50, 40}},
                          {4, {90, 80, 90}},
                          {5, {70, 70, 70}},
                          {6, {70, 80, 80}},
                          {7, {30, 20, 50}},
                          {8, {60, 70, 50}},
                          {9, {50, 60, 70}},
                          {10,{100,100,90}}
                        };

                      Comment

                      • smartway
                        New Member
                        • Oct 2006
                        • 24

                        #12
                        you will have to use 2D array for test

                        Comment

                        Working...