c language   Fill in the parts indicated by ► (meaning missing items).     /* This program prompts for the colors of three bands of a resistor, and displays the * value of the resistance in kilo-ohms based on a color code */ #include #include /* for pow*/ #include /* for toupper*/ #include /* for strlen*/ #define NOT_FOUND -1 /* constants */ #define SUB_1 10 #define SUB_2 7 int search(const char [][SUB_2], const char [], int); int main(void){ char reply, /* user reply*/ char_left; /* character left in the input stream*/ int i; int counter; /* counters */ int value; /* subscript of target found in list*/ double answer = 0.0; /* value of resistor in kilo-ohms*/ int no_error = 1; /* denotes no error */ /* initializing the array*/ char COLOR_CODES[SUB_1][SUB_2] = {"black", "brown", "red", "orange","yellow", "green", "blue", "violet", "gray", "white"}; char target[SUB_2]; /* target string array*/ do{ printf("Enter the colors of the resistor's three bands, beginning with\n"); printf("the band nearest the end. Type the colors in lowercase letters only, "); printf("NO CAPS.\n\n"); for(counter = 1; ►; counter++) { printf("Band %d => ", counter); scanf("%s", target); value = search(►, ►, SUB_1); /* searches for string*/ if(value != NOT_FOUND) { switch(counter){ case 1: answer = value * ►; break; case 2: answer += value; break; case 3 if (value>3) answer+=pow(►); else for(i = 0; ►; i++) answer /= 10; } } else no error = 0; /* if string not found*/ } if (►) printf("Resistance value: %.3f kilo-ohms\n\n", answer); else printf("Invalid Color: %s\n\n", target); printf("Do you want to decode another resistor?\n => "); scanf("%c%c", &char_left, &reply); printf("\n"); } } while(►); /* function takes as input a list of strings, its size, and a target string. Then, searches the list for the target and returns as its value the subscript of the target in the list. It returns -1 if target is not found. */ int search(const char COLOR_CODES[][SUB_2], const char target[], int size){ int i, j; /* counters */ int length, counter=0; int found = 0; /* indicates when string is found*/ int where = 0; /* location of target*/ length = strlen(►); for(i=0; ►; i++) { for(j = 0; j < length; j++) if(►== target[j]) counter++; if(counter == length) found = 1; else counter=0; } --i; if(found) where = ►; else where = ►; return where; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

c language

 

Fill in the parts indicated by ► (meaning missing items).

 

 

/*
This program prompts for the colors of three bands of a resistor, and displays the * value of the
resistance in kilo-ohms based on a color code
*/
#include <stdio.h>
#include <math.h> /* for pow*/
#include <ctype.h> /* for toupper*/
#include <string.h> /* for strlen*/
#define NOT_FOUND -1 /* constants */
#define SUB_1 10
#define SUB_2 7
int search(const char [][SUB_2], const char [], int);
int main(void){
char reply, /* user reply*/
char_left; /* character left in the input stream*/
int i;
int counter; /* counters */
int value; /* subscript of target found in list*/
double answer = 0.0; /* value of resistor in kilo-ohms*/
int no_error = 1; /* denotes no error */

/* initializing the array*/
char COLOR_CODES[SUB_1][SUB_2] = {"black", "brown", "red", "orange","yellow", "green",
"blue", "violet", "gray", "white"}; char target[SUB_2]; /* target string array*/
do{
printf("Enter the colors of the resistor's three bands, beginning with\n");
printf("the band nearest the end. Type the colors in lowercase letters only, ");
printf("NO CAPS.\n\n");
for(counter = 1; ►; counter++) {
printf("Band %d => ", counter);
scanf("%s", target);
value = search(►, ►, SUB_1);
/* searches for string*/
if(value != NOT_FOUND) {
switch(counter){
case 1:
answer = value * ►;
break;
case 2:
answer += value;
break;
case 3
if (value>3)
answer+=pow(►);
else
for(i = 0; ►; i++)
answer /= 10;
}
}
else
no error = 0; /* if string not found*/
}
if (►)
printf("Resistance value: %.3f kilo-ohms\n\n", answer);
else
printf("Invalid Color: %s\n\n", target);
printf("Do you want to decode another resistor?\n => ");
scanf("%c%c", &char_left, &reply);
printf("\n");
} } while(►);

/* function takes as input a list of strings, its size, and a target string. Then, searches the list for the
target and returns as its value the subscript of the target in the list. It returns -1 if target is not found.
*/
int search(const char COLOR_CODES[][SUB_2], const char target[], int size){
int i, j; /* counters */
int length, counter=0;
int found = 0; /* indicates when string is found*/
int where = 0; /* location of target*/
length = strlen(►);
for(i=0; ►; i++) {
for(j = 0; j < length; j++)
if(►== target[j])
counter++;
if(counter == length)
found = 1;
else
counter=0;
}
--i;
if(found)
where = ►;
else
where = ►;
return where;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education