Question

In: Computer Science

********************************************C PROGRAMMING************************************************************************************* char lname[][10]={"Johnson","Williams","Ling","Albin","Anderson","Baca","Birner","Dominguez","Aimino", "Armstron

********************************************C PROGRAMMING*************************************************************************************

char lname[][10]={"Johnson","Williams","Ling","Albin","Anderson","Baca","Birner","Dominguez","Aimino", "Armstrong","Beard","Calderon","Carter","Chaname","Chaney"};

char fname[][10] ={"Fred","Betty","Hector","Ross","Jason","Elisa","Dalton","Javier","Ann","Addison","Cindy","Yamil","Thomas","Bryan","Kris"};

char middle[] = {'N','L','X','L','O','L','M','B','S','T','J','C','P','D','Z'};

char city[][10] = {"Lakeland","Orlando","Tampa","Lakeland","Tampa","Lakeland","Orlando","Orlando", "Lakeland","Lakeland","Orlando","Tampa","Tampa","Lakeland","Orlando"};

Create a report that lists all of the cities that patients live in and provide a count for
each city of how many patients come from that city. Print this list out in alphabetical
order based on city name.

Solutions

Expert Solution

Please comment me if anything is required.

Code:

#include <stdio.h>
#include <string.h>

int main()
{
//all the data from the problem stored in the character arrays
char lname[][10]={"Johnson","Williams","Ling","Albin","Anderson","Baca","Birner","Dominguez","Aimino", "Armstrong","Beard","Calderon","Carter","Chaname","Chaney"};

char fname[][10] ={"Fred","Betty","Hector","Ross","Jason","Elisa","Dalton","Javier","Ann","Addison","Cindy","Yamil","Thomas","Bryan","Kris"};

char middle[] = {'N','L','X','L','O','L','M','B','S','T','J','C','P','D','Z'};

char city[][10] = {"Lakeland","Orlando","Tampa","Lakeland","Tampa","Lakeland","Orlando","Orlando", "Lakeland","Lakeland","Orlando","Tampa","Tampa","Lakeland","Orlando"};


printf("Patients full name last name middle name and their city details below\n*************************************\n");

//loop to print the patients first name, last name, middle name and their city
for(int i=0;i<10;i++)
{
  
printf("The patient %s %s %c is lives in %s\n",lname[i],fname[i],middle[i],city[i]);
}

//sorting the city array in alphabetical order using bubble sort
char temp[100];
for (int j=0; j<10-1; j++)
{
for (int i=j+1; i<10; i++)
{
if (strcmp(city[j], city[i]) > 0) //comparing the cities according to the alphabetical order
{
strcpy(temp, city[j]);
strcpy(city[j], city[i]);
strcpy(city[i], temp);
}
}
}
  
printf("\nBelow is the count for each city from each city how many patients come from in ascending order\n************************************\n");

int count = 0;

//counting the count of each city
for(int i=0;i<10;i++)
{
count = 1;
  
while(strcmp(city[i],city[i+1])==0)   
{
count++;
i++;
}
  
//printing the frequency of each city
printf("The number of patients lives in city %s is %d \n",city[i],count) ;
}

}

Output :


Related Solutions

for C program 10 by 10 char array. char 0-9 as rows and char a-j as...
for C program 10 by 10 char array. char 0-9 as rows and char a-j as collumns.
Write in C programming language Write the function replace(char b[], char f[], char t[]). which finds...
Write in C programming language Write the function replace(char b[], char f[], char t[]). which finds the string 'f' in the string 'b' and replaces it with the string 't'. You can assume that f and t same length Example: char string[] = "zap";     replace(string, "ap", "oo"); --changes 'string' to "zoo".     *don't assume substring being replaced is singular, or that its own substrings are unique.     *Don't re scan letters already checked and replaced         char string[] =...
in C programming language char character [100] = "hello"; a string array variable It is given....
in C programming language char character [100] = "hello"; a string array variable It is given. By writing a function called TranslateString, By accessing the pointer address of this given string, returning the string's address (pointer address) by reversing the string Write the function and use it on the main function. Function void will not be written as. Return value pointer address it will be. Sweat operation on the same variable (character) It will be made. Declaration of the function...
[ Write in C, not C++] Define a function char* deleteSymbol(char *s, char x) that removes...
[ Write in C, not C++] Define a function char* deleteSymbol(char *s, char x) that removes the character x from string s. For s[] = “America”, a call to deleteSymbol(s, ‘a’) converts s[] = “Ame”
A. Ling, Johnson, Lesley, and Miya commenced business and named their company as Moba Teknologi Sdn...
A. Ling, Johnson, Lesley, and Miya commenced business and named their company as Moba Teknologi Sdn Bhd. The company sells a ready-to-use software product, ML1 for the use of small businesses. The current selling price for the product is $500. Next year in 2020, the company planned to sell 7,300 units. The followings are information on the expenses: Cost of software $180 per unit Shipping and handling $20 per unit Annual fixed cost $1,200,000 Required: a. Calculate Moba Teknologi’s breakeven...
Transfer in MIPS char * strtoupper(char s[]) { char c; c = s[0]; /* empty string...
Transfer in MIPS char * strtoupper(char s[]) { char c; c = s[0]; /* empty string */ if (c == 0) return s; /* convert the first character to upper case*/ if (c >= ‘a’ && d <= ‘z’) { c -= 32; s[0] = c; } /* convert the remaining characters*/ strtoupper(s + 1); return s; }
Draw a memory layout to show the relations of a, b and c. char a[3][10] =...
Draw a memory layout to show the relations of a, b and c. char a[3][10] = {"abcdefg", "1234567", "!@#$%^&"}; char* b[3]; char** c; b[0] = &a[0][0]; b[1] = &a[1][0]; b[2] = &a[2][0]; c = b; char x = b[0][3]; char y = b[0][13];
Implement stack in C Struct: struct patients{ int id; int severity; char *firstName; char *lastName; char...
Implement stack in C Struct: struct patients{ int id; int severity; char *firstName; char *lastName; char *state; int time_spent; }; Given Array: struct patients* patientsArray[4] = {&p1, &p2, &p3, &p4}; Create two functions one for pushing this array to the stack and one for popping the variables such as p1 p2 p3 p4 by its ID
C Implement the function Append (char** s1, char** s2) that appends the second character array to...
C Implement the function Append (char** s1, char** s2) that appends the second character array to the first, replaces the first array with the result and replaces the second character array with the original first array. For example, if the first character array is "hello" and the second is "world" at the end of the function the new value of the first character array should be"helloworld" and the second array should be "hello". If the input is invalid the function...
Translate the following C++ program to Pep/9 assembly language. const char chConst = '+'; char ch1;...
Translate the following C++ program to Pep/9 assembly language. const char chConst = '+'; char ch1; char ch2; int main() { cin.get(ch1); cin.get(ch2);    cout << ch1 << chConst << ch2;    return 0; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT