custom init

main file



#import <Foundation/Foundation.h>
#import "TenthMarks.h"
#import "InterMarks.h"
int main(int argc, const char * argv[]) {
    
    TenthMarks * tenth = [[TenthMarks alloc]initWithTenthMarksForTeluguMarks:98 forHindiMarks:85 forEnglishMarks:89 forMathsMarks:85 forScienceMarks:87 forSocialMarks:85];
    
    InterMarks * inter = [[InterMarks alloc]initWithInterMarksForSanskrit1Marks:89 forenglish1Marks:74 forMaths1AMarks:75 forMaths1BMarks:85 forPhysics1Marks:87 forchemistry1Marks:85 forSanskrit2Marks:86 forenglish2Marks:98 formaths2AMarks:87 forMaths2BMarks:85 forPhysics2Marks:89 forChemistry2Marks:88];
    
    return 0;

}

TenthMarks.h

#import <Foundation/Foundation.h>

@interface TenthMarks : NSObject

-(id)initWithTenthMarksForTeluguMarks:(unsigned short int)telugumarks
                        forHindiMarks:(unsigned short int)hindiMarks
                      forEnglishMarks:(unsigned short int)englishMarks
                        forMathsMarks:(unsigned short int)mathsMarks
                      forScienceMarks:(unsigned short int)scienceMarks
                       forSocialMarks:(unsigned short int)socialMarks;


@end

Tenthmarks.m

#import "TenthMarks.h"
@implementation TenthMarks
-(id)initWithTenthMarksForTeluguMarks:(unsigned short int)telugumarks
                        forHindiMarks:(unsigned short int)hindiMarks
                      forEnglishMarks:(unsigned short int)englishMarks
                        forMathsMarks:(unsigned short int)mathsMarks
                      forScienceMarks:(unsigned short int)scienceMarks
                       forSocialMarks:(unsigned short int)socialMarks
{
    self = [super init];
    if (self) {
        unsigned short int passMarks=35;
        unsigned short int totalMarks;
        float percentage;
        NSLog(@"************Tenth Result***********");
        if (telugumarks>=passMarks && hindiMarks >= passMarks && englishMarks>=passMarks && mathsMarks>=passMarks && scienceMarks>=passMarks && socialMarks>=passMarks) {
            NSLog(@"Passed in Tenth");
        }
        else{
            NSLog(@"Failed in Tenth");
        }
        totalMarks=telugumarks+hindiMarks+englishMarks+mathsMarks+scienceMarks+socialMarks;
        percentage=(float)totalMarks/6;
        NSLog(@" Subjects        Marks         ");
        NSLog(@" Telugu           %i            ",telugumarks);
        NSLog(@" Hindi            %i            ",hindiMarks);
        NSLog(@" English          %i            ",englishMarks);
        NSLog(@" Maths            %i            ",mathsMarks);
        NSLog(@" Science          %i            ",scienceMarks);
        NSLog(@" Social           %i            ",socialMarks);
        NSLog(@"                 -----");
        NSLog(@" TotalMarks       %i            ",totalMarks);
        NSLog(@"                 -----");
        NSLog(@" Percentage       %f            ",percentage);
        NSLog(@"                 -----");
        
        if (percentage>=70) {
            NSLog(@"Distinction");
        } else if(percentage>=60 && percentage<70){
            NSLog(@"First Class");
        } else if (percentage>=50 && percentage<60){
            NSLog(@"Second Class");
        } else if (percentage<50){
            NSLog(@"Third Class");
        }
    }
    return self;
}

@end

InterMarks.h

#import <Foundation/Foundation.h>

@interface InterMarks : NSObject
-(id)initWithInterMarksForSanskrit1Marks:(unsigned short int)sanskrit1Marks
                        forenglish1Marks:(unsigned short int)english1Marks
                         forMaths1AMarks:(unsigned short int)maths1AMarks
                         forMaths1BMarks:(unsigned short int)maths1BMarks
                        forPhysics1Marks:(unsigned short int)physics1Marks
                      forchemistry1Marks:(unsigned short int)chemistry1Marks
                       forSanskrit2Marks:(unsigned short int)sanskrit2Marks
                        forenglish2Marks:(unsigned short int)english2Marks
                         formaths2AMarks:(unsigned short int)maths2AMarks
                         forMaths2BMarks:(unsigned short int)maths2BMarks
                        forPhysics2Marks:(unsigned short int)physics2Marks
                      forChemistry2Marks:(unsigned short int)chemistry2Marks;
@end

InterMarks.m

#import "InterMarks.h"

@implementation InterMarks

-(id)initWithInterMarksForSanskrit1Marks:(unsigned short int)sanskrit1Marks
                          forenglish1Marks:(unsigned short int)english1Marks
                           forMaths1AMarks:(unsigned short int)maths1AMarks
                           forMaths1BMarks:(unsigned short int)maths1BMarks
                          forPhysics1Marks:(unsigned short int)physics1Marks
                         forchemistry1Marks:(unsigned short int)chemistry1Marks
                       forSanskrit2Marks:(unsigned short int)sanskrit2Marks
                        forenglish2Marks:(unsigned short int)english2Marks
                         formaths2AMarks:(unsigned short int)maths2AMarks
                         forMaths2BMarks:(unsigned short int)maths2BMarks
                        forPhysics2Marks:(unsigned short int)physics2Marks
                      forChemistry2Marks:(unsigned short int)chemistry2Marks
{
    self = [super init];
    if (self) {
        
        unsigned short int passMarks=35;
        unsigned short int TotalMarks;
        unsigned short int FirstYearTotal;
        unsigned short int SecondYearTotal;
        float Percentage;
        NSLog(@"************Inter Result ***********");
        if (sanskrit1Marks>=passMarks && english1Marks>=passMarks && maths1AMarks>=passMarks && maths1BMarks>=passMarks && physics1Marks>=passMarks && chemistry1Marks>=passMarks && sanskrit2Marks>=passMarks && english2Marks>=passMarks && maths2AMarks>=passMarks && maths2BMarks>=passMarks && physics2Marks>=passMarks && chemistry2Marks>=passMarks) {
            NSLog(@"passed in Inter");
        } else {
            NSLog(@"Failed in Inter");
        }
        
       FirstYearTotal=sanskrit1Marks+english1Marks+maths1AMarks+maths1BMarks+physics1Marks+chemistry1Marks;
        SecondYearTotal=sanskrit2Marks+english2Marks+maths2AMarks+maths2BMarks+physics2Marks+chemistry2Marks;
        TotalMarks=FirstYearTotal+SecondYearTotal;
        Percentage=(float)TotalMarks/12;
        
        NSLog(@"  Subjects     FirstYear    SecondYear");
        NSLog(@"   Sanskrit      %i          %i",sanskrit1Marks,sanskrit2Marks);
        NSLog(@"   English       %i          %i",english1Marks,english2Marks);
        NSLog(@"   MathsA        %i          %i",maths1AMarks,maths2AMarks);
        NSLog(@"   MathsB        %i          %i",maths1BMarks,maths2BMarks);
        NSLog(@"   Physics       %i          %i",physics1Marks,physics2Marks);
        NSLog(@"   Chemistry     %i          %i",chemistry1Marks,chemistry2Marks);
        NSLog(@"                -----       -----");
        NSLog(@"   English       %i          %i",FirstYearTotal,SecondYearTotal);
        NSLog(@"                -----       -----");
                NSLog(@"%i",TotalMarks);
        NSLog(@"%f",Percentage);   
     
        if (Percentage>=70) {
            NSLog(@"Distinction");
        } else if(Percentage>=60 && Percentage<70){
            NSLog(@"First Class");
        } else if (Percentage>=50 && Percentage<60){
            NSLog(@"Second Class");
        } else if (Percentage<50){
            NSLog(@"Third Class");
        }
        
    }    
    return self;
}

@end
Previous
Next Post »