Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Specification For this programming assignment, you will implement of a C program for printing digits 0 , 1 , 2 , . . .

Problem Specification
For this programming assignment, you will implement of a C program for printing digits 0,1,
2,...,9 on console using three horizontal segments (a, g, and d) and four vertical segments
(f, b, e, and c) as depicted in Figure 1.
Figure 1: Top row from left to right depicts how digits 0-4 are represented using seven
segments. Bottom row from left to right depicts how digits 5-9 are represented using seven
segments.
To draw each horizontal segment, you need to print two rows of asterisks and to draw
each vertical segment, you need to print two columns of asterisks. The length of horizontal
and vertical segments will be given by the user of the program. Figure 2 is an example of
displaying digit 8 using seven segments made of asterisks.
2 Program Input
The program starts by displaying the following message:
This is a 7-segment display! Press Enter after providing any number in keyboard.
Please enter the length of horizontal segments (from 3 to 40):
After the user enters the length of horizontal segments using keyboard, your program will
check the entered length. If the length is less than 3 or greater than 40, the program must
1
****************
****************
****
****
****
****
****
****
****
****
****
****
****
****
****************
****************
****
****
****
****
****
****
****
****
****
****
****
****
****************
****************
Figure 2: How digit 8 is represented using asterisks. In this example, the length of each
horizontal segment is 16 asterisks and the length of each vertical segment is 12 asterisks.
print a message stating that the length is not acceptable and the user must try entering the
length again. When user enters an acceptable length for the horizontal segments, then, the
program prints out the following message on screen:
Now, enter the length of vertical segments (from 3 to 40):
After the user enters the length of vertical segments using keyboard, your program will
check the entered length. If the length is less than 3 or greater than 40, the program must
print a message stating that the length is not acceptable and the user must try entering the
length again. Also, if the length of vertical segment is greater than twice the length
of horizontal segment or less than half of the length of horizontal segment, the
program must print a message stating that the length is not acceptable and the user must try
entering the length again. When user enters an acceptable length for the vertical segments,
then, the program prints out the following message on screen:
Enter a positive integer:
After the user enters the positive integer, the program checks to see if the user input
is a valid positive integer. If the user input is not legal, the program must print out a
message stating that the user input is not acceptable and the user must try entering the
positive integer again. When user enters an acceptable input (a positive integer), the program
prints out the seven-segment representation of that number. Then, the program repeats this
process (printing the message Enter a positive integer: and printing out its seven-segment
representation) indefinitely.
To end this infinite loop, user can simply presses Ctrl + D , which is a way to pass
EOF character to the program via standard input stream (keyboard).
2
3 Submissions
You need to submit a .zip file compressing 1) the C source file(s) related to the assignment
(.c files),2) header file(s)(.h files) if any, 3) a snapshot of your Unix terminal running GDB
on your code (.jpg or .png file), and 4) a makefile. Please use sevenseg to name the
executable of your program in the makefile to make sure that the autograder can
successfully run your program. Starter code: #define MAX_LEN 100
#include
void main(void){
printf("This is a 7-segment display! Press \"Enter\" after providing any number in keyboard.
");
int segment_width;//width of horizontal segments in the 7-segment display
int input_error;//flag to show whether some error is detected in user's input
char string[MAX_LEN +1];//placeholder to hold user's input from keyboard
while(1){
printf("Please enter the length of horizontal segments (from 3 to 40):
");
input_error = segment_width =0;
for(int i =0; i MAX_LEN;i++){
if(i ==3){//Given input must be a 1 or 2-digit positive integer.
input_error =1;
break;
}
string[i]= getchar();
if(string[i]=='
'){//end of user's input
string[i]='\0';
break;
}else if(string[i]'0'|| string[i]>'9'){//not a digit is given by user
input_error =1;
break;
}else
segment_width =10* segment_width //accounts for previously entered digits...
+(string[i]-'0')//converting ASCII code of string[i] to its numerical value...
;//converting the #define MAX_LEN 100
#includestdio
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions