#include #include #include #include #include /** * @author theyawninchihua * Personal, noncommercial use of this code constitutes fair use. * This document may be updated without prior notice. */ typedef struct { char OEM[30], model[30], variant; bool SBRfront, SBRrear; char ISOFIX; bool TPMSreadout; int safeBehaviour; bool ESC, TPMSwarning; char BSM; bool FCW, AEBCCR, AEBped, LDW; int emergencyIntervention; bool threePointBelts; char sideThoraxAirbags, sideHeadAirbags;//nfr, nfta bool headRestraints, rearPretensioners, centreAirbag; int occupantRestraint; double overallScore; }rating; typedef struct { char name[30]; int count; rating* vehicles; }segment; void addScores(rating* vehicle) { vehicle->safeBehaviour=0; if(vehicle->SBRfront) vehicle->safeBehaviour=2; if(vehicle->SBRfront && (vehicle->ISOFIX=='y' || vehicle->ISOFIX=='1'|| vehicle->ISOFIX=='i')) { vehicle->safeBehaviour=4; if(vehicle->SBRfront && vehicle->ISOFIX=='i') vehicle->safeBehaviour=5; } if(vehicle->SBRfront && vehicle->SBRrear && (vehicle->ISOFIX=='y' || vehicle->ISOFIX=='1' || vehicle->ISOFIX=='i')) { vehicle->safeBehaviour=6; if(vehicle->ISOFIX=='i' && vehicle->TPMSreadout) vehicle->safeBehaviour=7; } vehicle->emergencyIntervention=0; if(vehicle->ESC) vehicle->emergencyIntervention=2; if(vehicle->ESC && vehicle->TPMSwarning) { vehicle->emergencyIntervention=4; if(vehicle->FCW || vehicle->AEBCCR || vehicle->LDW) vehicle->emergencyIntervention=5; } if(vehicle->ESC && vehicle->TPMSwarning && (vehicle->BSM=='w' || vehicle->BSM=='c' || vehicle->BSM=='1')) { vehicle->emergencyIntervention=6; if(vehicle->FCW && vehicle->AEBCCR && vehicle->AEBped && vehicle->LDW) vehicle->emergencyIntervention=7; } vehicle->occupantRestraint=0; if(vehicle->threePointBelts) vehicle->occupantRestraint=2; if(vehicle->threePointBelts && (vehicle->sideThoraxAirbags=='f' || vehicle->sideThoraxAirbags == '1' || vehicle->sideThoraxAirbags=='r')) { vehicle->occupantRestraint=4; if(vehicle->sideThoraxAirbags=='r' || vehicle->rearPretensioners || vehicle->centreAirbag) vehicle->occupantRestraint=5; } if(vehicle->threePointBelts && vehicle->headRestraints && (vehicle->sideThoraxAirbags=='f' || vehicle->sideThoraxAirbags == '1' || vehicle->sideThoraxAirbags=='r') && (vehicle->sideHeadAirbags=='a' || vehicle->sideHeadAirbags=='1')) { vehicle->occupantRestraint=6; if(vehicle->sideThoraxAirbags=='r' || vehicle->rearPretensioners || vehicle->centreAirbag) vehicle->occupantRestraint=7; } vehicle->overallScore=0.25*vehicle->safeBehaviour+0.25*vehicle->emergencyIntervention+0.5*vehicle->occupantRestraint; } void getDetails(rating* vehicle) { printf("\nNow accepting vehicle details.\n"); printf("\n- - - - - - - - - -\n"); printf("VARIANT INFORMATION\n"); printf("\nMANUFACTURER\n-Please stylise appropriately, using sentence case when in doubt.\n-Do not use spaces. Replace any spaces with underscores.\n>"); scanf("%s", vehicle->OEM); if(strlen(vehicle->OEM)>=4) { vehicle->OEM[0]=toupper(vehicle->OEM[0]); for(int i=1; vehicle->OEM[i]!='\0'; i++) vehicle->OEM[i]=tolower(vehicle->OEM[i]); } else { for(int i=0; vehicle->OEM[i]!='\0'; i++) vehicle->OEM[i]=toupper(vehicle->OEM[i]); } printf("\nMODEL\n-Do not use spaces. Replace any spaces with underscores.\n>"); scanf("%s", vehicle->model); for(int i=0; vehicle->model[i]!='\0'; i++) vehicle->model[i]=toupper(vehicle->model[i]); printf("\nVARIANT\n-Enter s for the standard variant fitted with only basic equipment\n-Enter m for a middle variant, fitted with an equipment level between the worst and best available\n-Enter o for the best equipped variant fitted with all safety options\n-Enter a if all variants have the same safety equipment\n>"); scanf(" %c", &vehicle->variant); printf("\n%s %s ", vehicle->OEM, vehicle->model); switch(vehicle->variant) { case 's': case 'S': printf("(with standard equipment)\n"); break; case 'm': case 'M': printf("(mid-variant)\n"); break; case 'o': case 'O': printf("(with optional equipment)\n"); break; case 'a': case 'A': printf("(all variants)\n"); break; } printf("\n- - - - - - - - - -\n"); printf("SAFE BEHAVIOUR\n"); printf("\nSBR FRONT\n-If the vehicle does not have audio-visual safety belt reminders for the driver and front passenger, enter 0\n-If the vehicle has audio-visual safety belt reminders for the driver and front passenger, enter 1\n>"); scanf("%d", &(vehicle->SBRfront)); printf("\nSBR REAR\n-If the vehicle does not have audio-visual safety belt reminders for all rear seating positions, enter 0\n-If the vehicle has audio-visual safety belt reminders for all rear seating positions, enter 1\n>"); scanf("%d", &(vehicle->SBRrear)); printf("\nISOFIX\n-If the vehicle does not have ISOFIX anchorages at both rear outboard seating positions, enter n\n-If the vehicle has conventional ISOFIX anchorages at both rear outboard seating positions, enter y\n-If the vehicle has i-Size compatible rear outboard seating positions, enter i\n>"); scanf(" %c", &(vehicle->ISOFIX)); printf("\nTPMS READOUT\n-If the vehicle does not have a tyre pressure/temperature readout, enter 0\n-If the vehicle has a tyre pressure/temperature readout, enter 1\n>"); scanf("%d", &(vehicle->TPMSreadout)); printf("\n- - - - - - - - - -\n"); printf("EMERGENCY INTERVENTION\n"); printf("\nESC\n-If the vehicle does not have an electronic stability control system, enter 0\n-If the vehicle has an electronic stability control system, enter 1\n>"); scanf("%d", &(vehicle->ESC)); printf("\nDEFLATION WARNING\n-If the vehicle does not have a tyre pressure loss warning, enter 0\n-If the vehicle has a tyre pressure loss warning, enter 1\n>"); scanf("%d", &(vehicle->TPMSwarning)); printf("\nBSM\n-If the vehicle does not have a blind spot monitor, enter n\n-If the vehicle has a blind spot warning lamp or alert, enter w\n-If the vehicle relays a blind spot camera feed to the driver, enter c\n>"); scanf(" %c", &(vehicle->BSM)); printf("\nFCW\n-If the vehicle does not have an audio-visual forward collision warning, enter 0\n-If the vehicle has an audio-visual forward collision warning, enter 1\n>"); scanf("%d", &(vehicle->FCW)); printf("\nAEB CCR\n-If the vehicle does not have an automatic emergency braking system that responds to other cars, enter 0\n-If the vehicle has an automatic emergency braking system that responds to other cars, enter 1\n>"); scanf("%d", &(vehicle->AEBCCR)); printf("\nAEB Ped\n-If the vehicle does not have an automatic emergency braking system that responds to pedestrians, enter 0\n-If the vehicle has an automatic emergency braking system that responds to pedestrians, enter 1\n>"); scanf("%d", &(vehicle->AEBped)); printf("\nLDW\n-If the vehicle does not have an audio-visual lane departure warning, enter 0\n-If the vehicle has an audio-visual lane departure warning, enter 1\n>"); scanf("%d", &(vehicle->LDW)); printf("\n- - - - - - - - - -\n"); printf("OCCUPANT RESTRAINT\n"); printf("\nTHREE-POINT BELTS FOR ALL\n-If the vehicle does not have three-point seatbelts for all seats, enter 0\n-If the vehicle has three-point seatbelts for all seats, enter 1\n>"); scanf("%d", &(vehicle->threePointBelts)); printf("\nSIDE THORAX AIRBAGS\n-If the vehicle does not have side thorax airbags, enter n\n-If the vehicle has side thorax airbags for only the driver and front passenger, enter f\n-If the vehicle additionally has side thorax airbags for at least one rear row, enter r\n>"); scanf(" %c", &(vehicle->sideThoraxAirbags)); printf("\nSIDE HEAD AIRBAGS\n-If the vehicle does not have side head airbags, enter n\n-If the vehicle has side head airbags for only the driver and front passenger, enter f\n-If the vehicle has three rows but has side head airbags for only one rear row, enter t\n-If the vehicle has side head airbags for all rows, enter a\n>"); scanf(" %c", &(vehicle->sideHeadAirbags)); printf("\nHEAD RESTRAINTS FOR ALL\n-If the vehicle does not have head restraints for all seats, enter 0\n-If the vehicle has head restraints for all seats, enter 1\n>"); scanf("%d", &(vehicle->headRestraints)); printf("\nREAR PRETENSIONERS\n-If the vehicle does not have safety belt pretensioners for at least the outboard second-row seats, enter 0\n-If the vehicle has safety belt pretensioners for at least the outboard second-row seats, enter 1\n>"); scanf("%d", &(vehicle->rearPretensioners)); printf("\nCENTRE AIRBAG\n-If the vehicle does not have a centre airbag between the front occupants, enter 0\n-If the vehicle has a centre airbag between the front occupants, enter 1\n>"); scanf("%d", &(vehicle->centreAirbag)); printf("\n- - - - - - - - - -\n"); } void printReport(rating vehicle) { printf("\nShowing safety equipment for %s %s ", vehicle.OEM, vehicle.model); switch(vehicle.variant) { case 's': case 'S': printf("(with standard equipment)\n"); break; case 'm': case 'M': printf("(mid-variant)\n"); break; case 'o': case 'O': printf("(with optional equipment)\n"); break; case 'a': case 'A': printf("(all variants)\n"); break; } printf("\n- - - - - - - - - -\n"); printf("SAFE BEHAVIOUR\n"); printf("%d max. 7 / ", vehicle.safeBehaviour); switch(vehicle.safeBehaviour) { case 7: printf("GOOD+\n"); break; case 6: printf("GOOD\n"); break; case 5: printf("ADEQUATE+\n"); break; case 4: printf("ADEQUATE\n"); break; case 2: printf("MODERATE\n"); break; default: printf("POOR\n"); break; } printf("\nSBR FRONT: %s\n", vehicle.SBRfront?"yes":"no"); printf("SBR REAR: %s\n", vehicle.SBRrear?"yes":"no"); printf("ISOFIX: "); switch(vehicle.ISOFIX) { case 'y': case '1': printf("yes\n"); break; case 'i': printf("i-Size\n"); break; default: printf("no\n"); break; } printf("TPMS READOUT: %s\n", vehicle.TPMSreadout?"yes":"no"); printf("\n- - - - - - - - - -\n"); printf("EMERGENCY INTERVENTION\n"); printf("%d max. 7 / ", vehicle.emergencyIntervention); switch(vehicle.emergencyIntervention) { case 7: printf("GOOD+\n"); break; case 6: printf("GOOD\n"); break; case 5: printf("ADEQUATE+\n"); break; case 4: printf("ADEQUATE\n"); break; case 2: printf("MODERATE\n"); break; default: printf("POOR\n"); break; } printf("\nESC: %s\n", vehicle.ESC?"yes":"no"); printf("DEFLATION WARNING: %s\n", vehicle.TPMSwarning?"yes":"no"); printf("BSM: "); switch(vehicle.BSM) { case 'c': printf("camera\n"); break; case 'w': case '1': printf("warning\n"); break; default: printf("no\n"); break; } printf("FCW: %s\n", vehicle.FCW?"yes":"no"); printf("AEB CCR: %s\n", vehicle.AEBCCR?"yes":"no"); printf("AEB Ped: %s\n", vehicle.AEBped?"yes":"no"); printf("LDW: %s\n", vehicle.LDW?"yes":"no"); printf("\n- - - - - - - - - -\n"); printf("OCCUPANT RESTRAINT\n"); printf("%d max. 7 / ", vehicle.occupantRestraint); switch(vehicle.occupantRestraint) { case 7: printf("GOOD+\n"); break; case 6: printf("GOOD\n"); break; case 5: printf("ADEQUATE+\n"); break; case 4: printf("ADEQUATE\n"); break; case 2: printf("MODERATE\n"); break; default: printf("POOR\n"); break; } printf("\nTHREE-POINT BELTS FOR ALL: %s\n", vehicle.threePointBelts?"yes":"no"); printf("SIDE THORAX AIRBAGS: "); switch(vehicle.sideThoraxAirbags) { case 'f': case '1': printf("front\n"); break; case 'r': printf("front+rear\n"); break; default: printf("no\n"); break; } printf("SIDE HEAD AIRBAGS: "); switch(vehicle.sideHeadAirbags) { case 'a': case '1': printf("all rows\n"); break; case 't': printf("two rows only\n"); break; case 'f': printf("front\n"); break; default: printf("no\n"); break; } printf("HEAD RESTRAINTS FOR ALL: %s\n", vehicle.headRestraints?"yes":"no"); printf("REAR PRETENSIONERS: %s\n", vehicle.rearPretensioners?"yes":"no"); printf("CENTRE AIRBAG: %s\n", vehicle.centreAirbag?"yes":"no"); printf("\n- - - - - - - - - -\n"); printf("OVERALL RATING\n"); printf("Overall score: %.2lf max. 7.00\n", vehicle.overallScore); printf("Judgment: "); if(vehicle.overallScore>=4.50 && vehicle.safeBehaviour>=4 && vehicle.emergencyIntervention>=4 && vehicle.occupantRestraint>=4) printf("BEST PICK\n"); else if(vehicle.overallScore>=3.00 && vehicle.safeBehaviour>=2 && vehicle.emergencyIntervention>=2 && vehicle.occupantRestraint>=2) printf("RECOMMENDED\n"); else if(vehicle.overallScore>=1.50) printf("FAIR\n"); else printf("NOT RECOMMENDED\n"); printf("\n- - - - - - - - - -\n"); } void createReport(rating vehicle) { char reportName[FILENAME_MAX]; strcpy(reportName, "2023 "); strcpy(reportName, vehicle.OEM); strcat(reportName, " "); strcat(reportName, vehicle.model); strcat(reportName, " "); switch(vehicle.variant) { case 's': case 'S': strcat(reportName, "(standard)"); break; case 'm': case 'M': strcat(reportName, "(mid)"); break; case 'o': case 'O': strcat(reportName, "(optional)"); break; case 'a': case 'A': strcat(reportName, "(all variants)"); break; } strcat(reportName, ".txt"); FILE* fp=fopen(reportName, "w"); if(fp==NULL) { printf("Could not create report. File %s not found.\n", reportName); return; } fprintf(fp, "Gobar New Car Rating and Assessment Project (Gobar NCRAP)\n"); fprintf(fp, "bit.ly/gobarncrap. Not affiliated with Global NCAP.\n"); fprintf(fp, "\nShowing safety equipment for %s %s ", vehicle.OEM, vehicle.model); switch(vehicle.variant) { case 's': case 'S': fprintf(fp, "(with standard equipment)\n"); break; case 'm': case 'M': fprintf(fp, "(mid-variant)\n"); break; case 'o': case 'O': fprintf(fp, "(with optional equipment)\n"); break; case 'a': case 'A': fprintf(fp, "(all variants)\n"); break; } fprintf(fp, "\n- - - - - - - - - -\n"); fprintf(fp, "SAFE BEHAVIOUR\n"); fprintf(fp, "%d max. 7 / ", vehicle.safeBehaviour); switch(vehicle.safeBehaviour) { case 7: fprintf(fp, "GOOD+\n"); break; case 6: fprintf(fp, "GOOD\n"); break; case 5: fprintf(fp, "ADEQUATE+\n"); break; case 4: fprintf(fp, "ADEQUATE\n"); break; case 2: fprintf(fp, "MODERATE\n"); break; default: fprintf(fp, "POOR\n"); break; } fprintf(fp, "\nSBR FRONT: %s\n", vehicle.SBRfront?"yes":"no"); fprintf(fp, "SBR REAR: %s\n", vehicle.SBRrear?"yes":"no"); fprintf(fp, "ISOFIX: "); switch(vehicle.ISOFIX) { case 'y': case '1': fprintf(fp, "yes\n"); break; case 'i': fprintf(fp, "i-Size\n"); break; default: fprintf(fp, "no\n"); break; } fprintf(fp, "TPMS READOUT: %s\n", vehicle.TPMSreadout?"yes":"no"); fprintf(fp, "\n- - - - - - - - - -\n"); fprintf(fp, "EMERGENCY INTERVENTION\n"); fprintf(fp, "%d max. 7 / ", vehicle.emergencyIntervention); switch(vehicle.emergencyIntervention) { case 7: fprintf(fp, "GOOD+\n"); break; case 6: fprintf(fp, "GOOD\n"); break; case 5: fprintf(fp, "ADEQUATE+\n"); break; case 4: fprintf(fp, "ADEQUATE\n"); break; case 2: fprintf(fp, "MODERATE\n"); break; default: fprintf(fp, "POOR\n"); break; } fprintf(fp, "\nESC: %s\n", vehicle.ESC?"yes":"no"); fprintf(fp, "DEFLATION WARNING: %s\n", vehicle.TPMSwarning?"yes":"no"); fprintf(fp, "BSM: "); switch(vehicle.BSM) { case 'c': fprintf(fp, "camera\n"); break; case 'w': case '1': fprintf(fp, "warning\n"); break; default: fprintf(fp, "no\n"); break; } fprintf(fp, "FCW: %s\n", vehicle.FCW?"yes":"no"); fprintf(fp, "AEB CCR: %s\n", vehicle.AEBCCR?"yes":"no"); fprintf(fp, "AEB Ped: %s\n", vehicle.AEBped?"yes":"no"); fprintf(fp, "LDW: %s\n", vehicle.LDW?"yes":"no"); fprintf(fp, "\n- - - - - - - - - -\n"); fprintf(fp, "OCCUPANT RESTRAINT\n"); fprintf(fp, "%d max. 7 / ", vehicle.occupantRestraint); switch(vehicle.occupantRestraint) { case 7: fprintf(fp, "GOOD+\n"); break; case 6: fprintf(fp, "GOOD\n"); break; case 5: fprintf(fp, "ADEQUATE+\n"); break; case 4: fprintf(fp, "ADEQUATE\n"); break; case 2: fprintf(fp, "MODERATE\n"); break; default: fprintf(fp, "POOR\n"); break; } fprintf(fp, "\nTHREE-POINT BELTS FOR ALL: %s\n", vehicle.threePointBelts?"yes":"no"); fprintf(fp, "SIDE THORAX AIRBAGS: "); switch(vehicle.sideThoraxAirbags) { case 'f': case '1': fprintf(fp, "front\n"); break; case 'r': fprintf(fp, "front+rear\n"); break; default: fprintf(fp, "no\n"); break; } fprintf(fp, "SIDE HEAD AIRBAGS: "); switch(vehicle.sideHeadAirbags) { case 'a': case '1': fprintf(fp, "all rows\n"); break; case 't': fprintf(fp, "two rows only\n"); break; case 'f': fprintf(fp, "front\n"); break; default: fprintf(fp, "no\n"); break; } fprintf(fp, "HEAD RESTRAINTS FOR ALL: %s\n", vehicle.headRestraints?"yes":"no"); fprintf(fp, "REAR PRETENSIONERS: %s\n", vehicle.rearPretensioners?"yes":"no"); fprintf(fp, "CENTRE AIRBAG: %s\n", vehicle.centreAirbag?"yes":"no"); fprintf(fp, "\n- - - - - - - - - -\n"); fprintf(fp, "OVERALL RATING\n"); fprintf(fp, "Overall score: %.2lf max. 7.00\n", vehicle.overallScore); fprintf(fp, "Judgment: "); if(vehicle.overallScore>=4.50 && vehicle.safeBehaviour>=4 && vehicle.emergencyIntervention>=4 && vehicle.occupantRestraint>=4) fprintf(fp, "BEST PICK\n"); else if(vehicle.overallScore>=3.00 && vehicle.safeBehaviour>=2 && vehicle.emergencyIntervention>=2 && vehicle.occupantRestraint>=2) fprintf(fp, "RECOMMENDED\n"); else if(vehicle.overallScore>=1.50) fprintf(fp, "FAIR\n"); else fprintf(fp, "NOT RECOMMENDED\n"); fprintf(fp, "\n- - - - - - - - - -"); printf("Report created in file \"%s\" in local directory.\n", reportName); fclose(fp); } void rateVehicle() { rating vehicle1; getDetails(&vehicle1); addScores(&vehicle1); printf("\n\n\n\n\nGobar New Car Rating and Assessment Project (Gobar NCRAP)\n"); printf("bit.ly/gobarncrap. Not affiliated with Global NCAP.\n"); printReport(vehicle1); printf("\nDo you want to create a report? (y/n)\n"); char opt[2]; scanf("%s", opt); if(strcmp(opt, "y")!=0&&strcmp(opt, "1")!=0) return; createReport(vehicle1); } void rateSegment() { segment segment1; printf("Enter segment name. Do not leave spaces.\n>"); scanf("%s", segment1.name); printf("Enter number of cars in segment (keep in mind models with multiple variants).\n>"); scanf("%d", &segment1.count); segment1.vehicles=malloc(segment1.count*sizeof(rating)); for(int i=0; i=0) { segment1.vehicles[j]=segment1.vehicles[j-1]; j--; } segment1.vehicles[j]=temp; } printf("\n\n\n\n\nGobar New Car Rating and Assessment Project (Gobar NCRAP)\n"); printf("bit.ly/gobarncrap. Not affiliated with Global NCAP.\n"); printf("\nVehicle safety equipment information report for %s\n", segment1.name); for(int i=0; i", segment1.name); char opt[2]; scanf("%s", opt); if(strcmp(opt, "y")!=0&&strcmp(opt, "1")!=0) { free(segment1.vehicles); return; } for(int i=0; i"); scanf("%d", &size); segment segments[size]; for(int k=0; k"); scanf("%s", segments[k].name); printf("Enter number of cars in segment (keep in mind models with multiple variants).\n>"); scanf("%d", &segments[k].count); for(int i=0; i=0) { segments[k].vehicles[j]=segments[k].vehicles[j-1]; j--; } segments[k].vehicles[j]=temp; } } printf("\n\n\n\n\nGobar New Car Rating and Assessment Project (Gobar NCRAP)\n"); printf("bit.ly/gobarncrap. Not affiliated with Global NCAP.\n"); for(int k=0; k", segments[k].name); char opt[2]; scanf("%s", opt); if(strcmp(opt, "y")!=0&&strcmp(opt, "1")!=0) { free(segments[k].vehicles); return; } for(int i=0; i"); scanf("%d", &opt); switch(opt) { case 1: rateVehicle(); break; case 2: rateSegment(); break; case 3: rateMultipleSegments(); break; default: printf("Exiting programme...\n"); } return 0; }