/*Programmer: Nihcolas Canning Program: Assignment 3 Course: IPC144A Instructor: Arta Kogan Date: December 6, 2013*/ #include #include #include #define START 1921 #define SIZE 18 #define DIVIDE 5 //function prototypes and structures struct NameRecord { char name[31]; int year; int frequency; }; void allCaps(char s[]); int getRawData(FILE* fp,struct NameRecord records[],int currSize); void setYearTotals(struct NameRecord records[], int size, int yearRangeTotal[]); void setNameYearTotals(char theName[],struct NameRecord records[], int size, int nameTotal[]); void getPerHundredThousand(int nameTotal[], int yearRangeTotal[], double perHundredThousand[]); void printData(double perHundredThousand[]); void graphPerHundredThousand(double perHundredThousand[]); int main() { int valid=1; char input=' '; char theName[100]={' '}; FILE *fp; struct NameRecord records[150000]; int currSize; int yearRangeTotal[SIZE]={0}; int nameTotal[SIZE]={0}; double perHundredThousand[SIZE]={0}; printf("Welcome to the Name Popularity Checker\n======================================\n"); while(valid) { currSize=0; printf("Please enter a name:"); scanf("%s",theName); allCaps(theName); printf("Number of Babies named %s per 100,000 births\n============================================\n", theName); fp=fopen("femalebabynames.txt", "r"); if(fp) { currSize=getRawData(fp,records,currSize); fclose(fp); fp=fopen("malebabynames.txt", "r"); if(fp) { currSize=getRawData(fp,records,currSize); fclose(fp); setYearTotals(records,currSize,yearRangeTotal); setNameYearTotals(theName,records,currSize,nameTotal); getPerHundredThousand(nameTotal,yearRangeTotal,perHundredThousand); printData(perHundredThousand); graphPerHundredThousand(perHundredThousand); printf("Do you wish to check another name (Y/N)?"); while((scanf("%c", &input))!='\n') { if(input=='n') { valid=0; } } } else { printf("Error opening file malebabynames.csv.\n Program shutting Down\n"); valid=0; } } else { printf("Error opening file femalebabynames.csv.\n Program shutting Down\n"); valid=0; } } return 0; } //function definitions void graphPerHundredThousand(double perHundredThousand[]) { printf("\n\n Graph\n=====================================================\n\n"); int a; int b=START; int c; int stars=0; double lowest=0; int remain=0; for(a=0;a=0.01) { if(a==0 || lowest