Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A survey to know the popularity of four cars (Ambassador, Fiat, Dolphin and Maru

ID: 3630625 • Letter: A

Question

A survey to know the popularity of four cars (Ambassador, Fiat, Dolphin and Maruti) was conducted in four cities (Bombay, Calcutta, Delhi and Madras). Each person surveyed was asked to give his city and the type of car he was using. The results, in coded form, are tabulated as follows:

M 1 C 2 B 1 D 3 M 2 B 4
C 1 D 3 M 4 B 2 D 1 C 3
D 4 D 4 M 1 M 1 B 3 B 3
C 1 C 1 C 2 M 4 M 4 C 2
D 1 C 2 B 3 M 1 B 1 C 2
D 3 M 4 C 1 D 2 M 3 B 4
Codes represent the following information:
M - Madras 1 - Ambassador
D – Delhi 2 - Fiat
C – Calcutta 3 - Dolphin
B – Bombay 4 - Maruti
Write a program to produce a table showing popularity of various cars in four cities

Explanation / Answer

main() { int i, j, car; int frequency[5][5] = { {0},{0},{0},{0},{0} }; char city; printf("For each person, enter the city code "); printf("followed by the car code. "); printf("Enter the letter X to indicate end. "); /*. . . . . . TABULATION BEGINS . . . . . */ for( i = 1 ; i < 100 ; i++ ) { scanf("%c", &city ); if( city == 'X' ) break; scanf("%d", &car ); switch(city) { case 'B' : frequency[1][car]++; break; case 'C' : frequency[2][car]++; break; case 'D' : frequency[3][car]++; break; case 'M' : frequency[4][car]++; break; } } /*. . . . .TABULATION COMPLETED AND PRINTING BEGINS. . . .*/ printf(" "); printf(" POPULARITY TABLE "); printf("------------------------------------------- "); printf("City Ambassador Fiat Dolphin Maruti "); printf("------------------------------------------- "); for( i = 1 ; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote