1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Test your ability to work with records and arrays.

Discussion in 'C++' started by OM MAJED, Nov 13, 2010.

  1. OM MAJED

    OM MAJED New Member

    Joined:
    Nov 12, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    test your ability to work with records and arrays.
    Given the following two arrays with their initializations:
    AnsiString StudentName[5]={“Aliâ€, “Ranaâ€, “Samiâ€, “Hudaâ€, “Ramiâ€};
    int StudentMark[5]={80,76, 85, 92, 67};
    Write a C++ program to accomplish the followings (all in one program):
    a. declare a structure of two variables: StudentName and StudentMark of type string and integer respectively and then define an object of 5 records.
    b. copy all data of each array to its corresponding variable name of the defined records such that (“Ali†and 80) represents the first record and so on for the rest of data.
    c. using the declared structure, count and print number of PASS students if you know that the passing mark is 50.
    d. again, use the declared structure to find and print the maximum two marks (use a nested loops for this)
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    Dnt test our ability just say do u want ur homework to be done? Please this attitude will never fetch u any solution..try urself a bit then we would help u...
     
  3. OM MAJED

    OM MAJED New Member

    Joined:
    Nov 12, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include <vcl.h> 
    #include "MT262io.h" 
    #pragma hdrstop 
    #include <iostream.h> 
    #include<string.h> 
    //--------------------------------------------------------------------------- 
    #pragma argsused 
    struct Student 
     { 
      String  StudentName  ; 
      int     StudentMark  ; 
     }   ; 
    //--------------------------------------------------------------------------- 
     int main(int argc, char* argv[]) 
    
     { 
    
    AnsiString StudentName[5]={"Ali ", "Rana", "Sami", "Huda", "Rami"}; 
    int StudentMark[5]={80,76, 85, 92 , 67}; 
    
    
    Student MT262[5]  ; 
    
    for (int COUNT=0 ; COUNT <5 ;COUNT ++) 
      { 
      MT262[COUNT].StudentName = StudentName[COUNT] ; 
      MT262[COUNT].StudentMark = StudentMark[COUNT] ; 
      } 
    
      int PASS =0 ; 
      for (int P=0 ; P <5 ; P++) 
           if ( MT262[P].StudentMark >= 50 ) 
                PASS ++ ; 
       WriteIntPrCr("PASS =  " ,PASS ) ; 
    
     String  W ; 
      int    F ; 
    
      for (int c=0 ; c < 4 ; c++) 
           for (int N=c+1 ; N <5 ; N++) 
                if (MT262[N].StudentMark > MT262[c].StudentMark) 
                  { 
                    F = MT262[c].StudentMark    ; 
                    MT262[c].StudentMark = MT262[N].StudentMark  ; 
                    MT262[N].StudentMark = F  ; 
                    W = MT262[c].StudentName    ; 
                    MT262[c].StudentName = MT262[N].StudentName  ; 
                    MT262[N].StudentName = W  ; 
                  } 
    
    
    
     for (int c=0 ; c < 2 ;c++) 
              { 
               WriteString(MT262[c].StudentName) ; 
               WriteIntPrCr(" = " , MT262[c].StudentMark) ; 
              } 
    
    getchar() ; 
     return 0; 
    } 
    //-----------------------------------------------------------------------  
    this is my work give me your opiniON MESTTER techforum4u THANK YOU FOR YOUR HELP.
     
  4. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    7
    Trophy Points:
    0
    So what you are stuck at?
     

Share This Page