Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please write the code in c language and please put the main first and put all the 6 functions required in the code please do

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

please write the code in c language and please put the main first and put all the 6 functions required in the code please

do not forget getinteger

see the last screenshot these are the things that needs to be within main

ConvertDec_to_Hex-Oct-Bin.c is a simple conversion program that prompts the user for their name, followed by a prompt for an integer in the range [11,000,000] inclusive (or " x " to exit the program). The integer entered will be displayed in decimal, hexadecimal, octal, and binary representation. Hexadecimal, octal, and binary representations must be computed algorithmically (i.e. NOT accomplished via format specifier). The above mentioned display shall occur from within main0. The user is then asked if the output should be saved to a text file. If user replies in the affirmative, a name for the text file is requested. The newly created text file will contain the user's name, current date, and output results. The program loops until " x " is entered to exit. The current date shall be provided by char getDateAndTime 0 as discussed in the lecture notes. Example user interface: Enter your name: Hal Greenwald Enter an Integer [11,000,000] or type x to exit: 2000000 Error: 2000000 is out of range Enter an Integer [11,000,000] or type x to exit: 240 Decimal: 240 Hexadecimal: F0 Octal: 360 Binary: 11110000 Save to a file? (y):x Error: illegal value Save to a file? (y):y Enter file name: cs222 hw3.txt File saved. Enter an Integer [11,000,000] or type x to exit: x Goodbye! Terminal output: \$cat cs222_hw3.txt Hal Greenwald Today's date: Mon Feb 20 3:49:30 2023 Decimal: 240 Hexadecimal: F0 Octal: 360 Binary: 11110000 User defined functions: As a minimum, include the following 6 user-defined functions, all of which should be prototyped, and called from within main(.) char *getDateAndTime0; Returns a character string with the current date and time int getInteger0 Read user input into a character string using fgets O. " x " returns 1 indicating program exit. Otherwise, convert the string into an integer (which will be returned to main 0 ) using int atoi(const char str); or int sscanf(const char *s, const char *format, ...); void decimalToBinary(int decValue, char binString[]); Accepts a decimal value decValue and a character string buffer binString[]. Convert decvalue into its corresponding binary value and store the result as a character string within binString []. binString[] may then be displayed from within main 0. void decimalToHex(int decValue, char hexString[]); Accepts a decimal value decValue and a character string buffer hexString[]. Convert decvalue into its corresponding hexadecimal value and store the result as a character string within hexString[]. hexString[] may then be displayed from within main(). void decimalTooct(int decValue, char octString[]); Accepts a decimal value decValue and a character string buffer octString[]. Convert decvalue into its corresponding octal value and store the result as a character string within octString[]. octString may then be displayed from within main0. int saveFile(char name[], char date[], int decValue, char octString[], char hexString[], char binString[]); Prompt the user whether the output should be saved to a text file. If user replies in the affirmative, a name for the text file is requested. The newly created text file will contain the user's name, current date, and output results. If the output file cannot be opened, print an appropriate error message and return 0. Otherwise return 1; Rubric 10 points: - Is the source code well formatted using clearly readable indentation and white space (while viewed within vi) and well commented? 1 point - Range checking for numeric input [11,000,000]1 point - Save to a file? (y): If any character other than ' y ' or ' n ' is entered. An error message is displayed and the user is re-prompted. 1 point - Are each of the 6 above mentioned UDFs properly implemented? 1 point each. (6 points total) - Is the output (text file) correct and accessible? 1 points - Function prototypes are required for each UDF other than main0. 1 point will be deducted if prototypes are omitted or incorrect. - No global variables are permitted for this exercise. 1 point will be deducted for every global variable used. int main( pseudocode: int main( char dateTime[32]; char name[32]; char binString[32]; char octString[32]; char hexString[32]; int decVal = 0; int saveSuccess = 0; strcpy(dateTime,getDateAndTime0); prompt user for name decVal = getInteger(); // exit clause if (decVal == -1) return 0; // run conversions decimalToBinary(decVal, binString); decimalToHex(decVal, hexString); decimalToOct(decVal, octString); // print conversions to the console printf("Decimal: \%d \ n", decVal); printf("Binary: \%s \ n", binString); printf("Octal: \%s \ n", octString); printf("Hexidecimal: \%s \ n", hexString); // save the file saveSuccess = saveFile(name, date, decValue, octString

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

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions