Assistance with C coding.
Hi, so I require assistance upon a C lab assignment. Time is very much of the essence. Write a C code, complete with the main driver and corresponding functions, that asks the user for a zip code and prints the bar code. Use : for half bars, | for full bars. For example, 95014 becomes ||:|:::|:|:||::::::||:|::|:::|||
Time is very much limited!
C Code:
#include <stdio.h>
int sumOfDigits(input){
if(input/10 == 0){
return input;
}
return input%10 + sumOfDigits(input/10);
}
int checkNumber(int n){
if (n == 0 || n % 10 == 0){
return 0;
}
return ((n % 10) - 10) * (-1);
}
void printDigit(int n){
if(n==1){
printf(":::||");
}
if(n==2){
printf("::|:|");
}
if(n==3){
printf("::||:");
}
if(n==4){
printf(":|::|");
}
if(n==5){
printf(":|:|:");
}
if(n==6){
printf(":||:");
}
if(n==7){
printf("|:::|");
}
if(n==8){
printf("|::|:");
}
if(n==9){
printf("|:|::");
}
if(n==0){
printf("||:::");
}
}
void printBarCode(int zipCode){
int n = 1000000;
printf("|");
while (n / 10 != 0){
n /=10;
printDigit(zipCode / n % 10);
}
printf("|");
}
int main(){
int input, n, zipcode, sum;
printf("Enter a zip code: ");
scanf("%d", &input);
sum = sumOfDigits(input);
zipcode = input *10 + checkNumber(sum);
printf("Zip in Barcode\n");
printBarCode(zipcode);
return 0;
}
Output:
Please rate the answer if you find it helpful...:)
Assistance with C coding. Hi, so I require assistance upon a C lab assignment. Time is...
Reading and Writing Complete Files in C: The first part of the lab is to write a program to read the complete contents of a file to a string. This code will be used in subsequent coding problems. You will need 3 functions: main(), read_file() and write_file(). The main function contains the driver code. The read_file() function reads the complete contents of a file to a string. The write_file() writes the complete contents of a string to a file. The...
Help on coding this in c++. I am confused as how to go
about this problems!
IZzes 1. (Metric - English units Conversion) nferences A metric ton is 35,273.92 ounces. Write a C++ program to read the weight of a box of cereal in ounces then output this weight in metric tons, along with the number of boxes to yield a metric ton of cereal. llaborations at Design: To convert 14 ounces (of cereal) to metric tons, we use the...
In the program, the zipcode will be represented by an integer and the corresponding barcode will be represented by a string of digits. The digit 1 will represent the long bar, and the digit 0 will represent the short bar, The first and last digits of a POSTNET code are always 1. Stripping these leaves 25 digits, which can be split into groups of 5. The above example translates into the following string and groups of five: 101100100010010101100110001 01100 10001...
Assignment Overview This programming assignment is intended to demonstrate your knowledge of the following: Writing a while loop Writing a for loop Writing a while loop with a sentinel value Chocolate Coupons Foothill Fro-cho, LLC, gives customers a coupon every time they purchase a chocolate bar. After they earn a certain number of coupons, they qualify for a free chocolate bar, which they may use toward the purchase of a single chocolate bar. Usually, 7 is the...
c++ CSI Lab 6 This program is to be written to accomplish same objectives, as did the program Except this time we modularize our program by writing functions, instead of writing the entire code in main. The program must have the following functions (names and purposes given below). Fot o tentoutefill datere nedefremfite You will have to decide as to what arguments must be passed to the functions and whether such passing must be by value or by reference or...
i need help making this C++ code. Lab #2 Assignments: Numbers Class that translate whole dollar amounts in the range 0 through 9999 into an English description of the number. Numbers Class Design a class numbers that can be used to translate whole dollar amounts in the range 0 through 9999 into an English description of the number. For example, the number 713 would be translated into the string seven hundred thirteen, and 8203 would be translated into eight thousand...
Lanuage C++ (Beginner level) Please...I need help with this assignment If I still have question, can i contact you? -------------------------- Program 1 - WRITE ALL THE CODE in ONE FILE... MyArrayPtrArith1.cpp Step 1 - Define the class Write a class, myArrayClass, that creates an integer array. * Add an 'arraySize' variable, initialize to zero ( default constructor function ) * Create int * ptrArray ( default constructor set to NULL ) * Add a default constructor ( see above for...
Malloc function
For the prelab assignment and the lab next week use malloc
function to allocate space (to store the string) instead of
creating fixed size character array. malloc function allows user to
allocate memory (instead of compiler doing it by default) and this
gives more control to the user and efficient allocation of the
memory space.
Example
int *ptr
ptr=malloc(sizeof(int)*10);
In the example above integer pointer ptr is allocated a space of
10 blocks this is same as creating...
C++ i want Lab#3 done can u make clear code so I could understand it. Lab#2The objective of this lab is compare the populations of various cities that lie in between Toledo and Dayton on I-75. Write a program that produces a bar illustrating the populations. The program should read the name of the city and its population from a file. Have the program continue this process until the end of file is reached. For each city, your program should...
I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account: Customer name Customer address City State ZIP code Telephone Account balance Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...