Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3599324
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:21:12+00:00 2026-05-18T20:21:12+00:00

I’m new to objective-c and programming in general. I’m a paramedic and I’ve decided

  • 0

I’m new to objective-c and programming in general. I’m a paramedic and I’ve decided to learn to program in objective. I’ve got some experience with c, which is why this program is coded this way. I was wondering if there were a more efficient way to code this with objective-c? Thank you. (The program compiles without errors, so if there’s a syntax error somewhere in there it’s probably because i’m new to escaping characters on boards within the code blocks)


#import <Foundation/Foundation.h>

void calcDiagnosis (float pHInput, int paCO2Input, int hCO3Input);

int main (int argc, const char * argv[]){
 int i;
 int repeat;
 i = 0;
 for(i = 0; i < 3; i++){
 //Initialize lab value variables
 float pH;
 int paCO2;
 int hCO3;

 //Introduction
 NSLog(@"Welcome to the ABG Lab Value Interpreter v1.0\n");
 NSLog(@"Please enter the necessary values.\n");

 //Gather the necessary values
 NSLog(@"Enter the pH value:");
 scanf("%f", &pH);
 NSLog(@"Enter the PaCO2 value:");
 scanf("%i", &paCO2);
 NSLog(@"Enter the HCO3 value:");
 scanf("%i", &hCO3);
 calcDiagnosis (pH, paCO2, hCO3);

 //Control Loop
 NSLog(@"Again?\n 1: Yes\n 2: No");
 scanf("%i", &repeat);

 switch (repeat){
 case 1: 
  i = 0;
  break;
 case 2:
  i = 3;
  break;
  }
 }

        return 0;
}

void calcDiagnosis (float pHInput, int paCO2Input, int hCO3Input)
{
 //Transfer the arguments to new variables
 float pH = pHInput;
 int paCO2 = paCO2Input;
 int hCO3 = hCO3Input;

 //////////////////////////////////
 //Diagnose Respiratory Acidosis//
 ////////////////////////////////

  //Acute
 if ((pH < 7.35) && (paCO2 > 45) && (hCO3 >=22 && hCO3 <=26)) {
  NSLog(@"Acute Respiratory Acidosis");
  }
  //Partially Compensated
 if ((pH < 7.35) && (paCO2 > 45) && (hCO3 >26)) {
  NSLog(@"Partially Compensated Respiratory Acidosis");
  }
  //Compensated
 if ((pH >= 7.35 && pH <= 7.45) && (paCO2 > 45) && (hCO3 >26)) {
  NSLog(@"Compensated Respiratory Acidosis");
  }

 ///////////////////////////////////
 //Diagnose Respiratory Alkalosis//
 /////////////////////////////////

  //Acute
 if ((pH > 7.45) && (paCO2 < 35) && (hCO3 >=22 && hCO3 <=26)) {
  NSLog(@"Acute Respiratory Alkalosis");
  }
  //Partially Compensated
 if ((pH > 7.45) && (paCO2 < 35) && (hCO3 <22)) {
  NSLog(@"Partially Compensated Respiratory Alkalosis");
  }
  //Compensated
 if ((pH >= 7.35 && pH <= 7.45) && (paCO2 < 35) && (hCO3 <22)) {
  NSLog(@"Compensated Respiratory Alkalosis");
  }

 //////////////////////////////////
 //Diagnose Metabolic Acidosis////
 ////////////////////////////////

  //Acute
 if ((pH < 7.35) && (paCO2 >= 35 && paCO2 <= 45) && (hCO3 <22)) {
  NSLog(@"Acute Metabolic Acidosis");
  }
  //Partially Compensated
 if ((pH < 7.35) && (paCO2 < 35) && (hCO3 >22)) {
  NSLog(@"Partially Compensated Metabolic Acidosis");
  }
  //Compensated
 if ((pH >= 7.35 && pH <= 7.45) && (paCO2 < 35) && (hCO3 <22)) {
  NSLog(@"Compensated Metabolic Acidosis");
  }

 //////////////////////////////////
 //Diagnose Metabolic Alkalosis///
 ////////////////////////////////

  //Acute
 if ((pH > 7.45) && (paCO2 >= 35 && paCO2 <= 45) && (hCO3 >26)) {
  NSLog(@"Acute Metabolic Alkalosis");
  }
  //Partially Compensated
 if ((pH > 7.45) && (paCO2 > 45) && (hCO3 >26)) {
  NSLog(@"Partially Compensated Metabolic Alkalosis");
  }
  //Compensated
 if ((pH >= 7.35 && pH <= 7.45) && (paCO2 > 45) && (hCO3 >26)) {
  NSLog(@"Compensated Metabolic Alkalosis");
  }

 //////////////////////
 //Diagnosis Normal///
 ////////////////////
 if ((pH >= 7.35 && pH <= 7.45) && (paCO2 >= 35 && paCO2 <= 45) && (hCO3 >= 22 && hCO3 <= 26)) {
  NSLog(@"Normal Values");
  }
 return;
}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:21:13+00:00Added an answer on May 18, 2026 at 8:21 pm

    This can be a difficult question. As you get more experienced you will become more comfortable with more advanced concepts. The problem you are working on is actually quite sophisticated and makes for a great training tool.

    Your biggest issue is that your current solution does not use any object orientation, which can make it more difficult to maintain and/or expand in the future.

    Ultimately, the question of the optimal code structure can have many answers and you may not know which is better until farther down the line until you have added more functionality to your program.

    I have re-rendered your program, in what I feel is a solid end game structure (as opposed to shooting for a more meek intermediate step). Unfortunately, this may be a bit of a leap when just starting out.

    There are two advanced concepts in this solution, object oriented programming and selectors. Selectors are an incredibly powerful tool that allow you to pass actual instructions around your program using variables. In your case, you can store the if statements in your Diagnosis Objects.

    At any rate, please feel free to ask any questions about the following:

    Vitals.h

    #import <Foundation/Foundation.h>
    
    @interface Vitals : NSObject {
        float _pH;
        int _paCO2;
        int _hCO3;
    }
    
    - (id) initWithPH:(float)pH paCO2:(int)paCO2 hCO3:(int)hCO3;
    
    - (float) pH;
    - (int) paCO2;
    - (int) hCO3;
    
    @end
    

    Vitals.m

    #import "Vitals.h"
    
    @implementation Vitals
    
    - (id) initWithPH:(float)pH paCO2:(int)paCO2 hCO3:(int)hCO3 {
        if (self = [super init]) {
            _pH = pH;
            _paCO2 = paCO2;
            _hCO3 = hCO3;
        }
        return self;
    }
    
    - (float) pH {return _pH;}
    - (int) paCO2 {return _paCO2;}
    - (int) hCO3 {return _hCO3;}
    
    @end
    

    Diagnosis.h

    #import <Foundation/Foundation.h>
    @class Vitals;
    
    @interface Diagnosis : NSObject {
        NSString* _name;
        id _delegate;
        SEL _test;
    }
    
    - (id) initWithName:(NSString*)name delegate:(id)delegate test:(SEL)test;
    
    - (NSString*) name;
    
    - (BOOL) test:(Vitals*)vitals;
    
    @end
    

    Diagnosis.m

    #import "Diagnosis.h"
    
    @implementation Diagnosis
    
    - (id) initWithName:(NSString*)name delegate:(id)delegate test:(SEL)test {
        if (self = [super init]) {
            _name = [name retain];
            _delegate = delegate;
            _test = test;
        }
        return self;
    }
    - (void) dealloc {
        [_name release];
        [super dealloc];
    }
    
    - (NSString*) name {return _name;}
    
    - (BOOL) test:(Vitals*)vitals {
        return [(NSNumber*)[_delegate performSelector:_test withObject:vitals] boolValue];
    }
    
    @end
    

    Doctor.h

    #import <Foundation/Foundation.h>
    @class Vitals;
    @class Diagnosis;
    
    @interface Doctor : NSObject {
        NSMutableArray* _diagnoses;
    }
    
    - (void) learnDiagnosis:(Diagnosis*)diagnosis;
    
    - (Diagnosis*) diagnose:(Vitals*)vitals;
    
    @end
    

    Doctor.m

    #import "Diagnosis.h"
    #import "Doctor.h"
    
    @implementation Doctor
    
    - (id) init {
        if (self = [super init]) {
            _diagnoses = [[NSMutableArray alloc] init];
        }
        return self;
    }
    - (void) dealloc {
        [_diagnoses release];
        [super dealloc];
    }
    
    - (void) learnDiagnosis:(Diagnosis*)diagnosis {
        [_diagnoses addObject:diagnosis];
    }
    
    - (Diagnosis*) diagnose:(Vitals*)vitals {
        for (Diagnosis* diagnosis in _diagnoses) {
            if ([diagnosis test:vitals])
                return diagnosis;
        }
        return 0;
    }
    
    @end
    

    Differential.h

    #import <Foundation/Foundation.h>
    
    @interface Differential : NSObject {}
    
    - (void) teach:(Doctor*)doctor;
    
    @end
    

    Differential.m

    #import "Vitals.h"
    #import "Diagnosis.h"
    #import "Doctor.h"
    #import "Differential.h"
    
    @implementation Differential
    
    - (NSNumber*) acuteRespiratoryAcidosis:(Vitals*)vitals {
        return [NSNumber numberWithBool:(([vitals pH] < 7.35) && ([vitals paCO2] > 45) && ([vitals hCO3] >=22 && [vitals hCO3] <=26))];
    }
    - (NSNumber*) partiallyCompensatedResporatoryAcidosis:(Vitals*)vitals {
        return [NSNumber numberWithBool:(([vitals pH] < 7.35) && ([vitals paCO2] > 45) && ([vitals hCO3] >26))];
    }
    
    - (void) teach:(Doctor*)doctor {
        Diagnosis* diagnosis;
    
        diagnosis = [[Diagnosis alloc] initWithName:@"Acute Respiratory Acidosis" delegate:self test:@selector(acuteRespiratoryAcidosis:)];
        [doctor learnDiagnosis:diagnosis];
        [diagnosis release];
    
        diagnosis = [[Diagnosis alloc] initWithName:@"Partially Compensated Respiratory Acidosis" delegate:self test:@selector(partiallyCompensatedResporatoryAcidosis:)];
        [doctor learnDiagnosis:diagnosis];
        [diagnosis release];
    }
    
    @end
    

    Sandbox.h

    #import <Foundation/Foundation.h>
    #import "Vitals.h"
    #import "Diagnosis.h"
    #import "Doctor.h"
    #import "Differential.h"
    
    void run () {
        float pH=7.2;
        int paCO2=47;
        int hCO3=25;
    
        Doctor* doctor = [[Doctor alloc] init];
        Differential* differential = [[Differential alloc] init];
        [differential teach:doctor];
    
        Vitals* vitals = [[Vitals alloc] initWithPH:pH paCO2:paCO2 hCO3:hCO3];
    
        Diagnosis* diagnosis = [doctor diagnose:vitals];
        NSLog(@"%@",[diagnosis name]);
    
        [vitals release];
        [differential release];
        [doctor release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I want use html5's new tag to play a wav file (currently only supported
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.