Question: Please do lab on linux terminal and use gedit as editor and zoom in for better vision Please zoom in for better vision CPSC 1110

Please do lab on linux terminal and use gedit as editor and zoom in for better vision
Please do lab on linux terminal and use gedit as editor and
zoom in for better vision Please zoom in for better vision CPSC
1110 Fall 2020, Programming Assignment 1: Sum of Digits Due 11:59:59 pm
on due date 1. Overview The purpose of this assignment is to
Please zoom in for better vision give you some experience using loops & conditionals, as well as printf
& scanf, declaring variables, and using logical expressions. 2. More Assignment Specifics
This program will prompt the user to enter in a non-negative integer
in decimal (base 10). The sum of digits of the number value

CPSC 1110 Fall 2020, Programming Assignment 1: Sum of Digits Due 11:59:59 pm on due date 1. Overview The purpose of this assignment is to give you some experience using loops & conditionals, as well as printf & scanf, declaring variables, and using logical expressions. 2. More Assignment Specifics This program will prompt the user to enter in a non-negative integer in decimal (base 10). The sum of digits of the number value entered will be calculated starting with base 10 representation (as the number was typed) down through base 2 (binary) representation and the sum of digits of the number in each base representation will be displayed. The number value itself does not need to be displayed in any other base representation. As an example given the number input as 23: Base 10: 23/10 = 2R3 -> 2/10 - OR2 (end with 0), add remainders 3+2 -> sum of digits is 5 Base 9: 23/9-2RS -> 2/9 - OR2, 5+2 -> sum of digits is 7 Base 8: 23/8 = 2R7 -> 2/8 - 0R2, 7+2 -> sum of digits is 9 Base 7: 23/7 = 3R2 -> 3/70R3, 2+3 -> sum of digits is 5 Base 6: 23/6 - 3R5 -> 3/6 - OR3, 5+3 -> sum of digits is 8 Base 5: 23/ 54R3 -> 4/5 = OR4, 3+4 -> sum of digits is 7 Base 4:23/4-5R3 -> 5/4 = 1R1 -> 1/40R1, 3+1+1 -> sum of digits is 5 Base 3:23/3 - 7R2-> 7/3 =2R1 -> 2/3 - OR2, 2+1+2 -> sum of digits is s Base 2:23/2 - 11R1 -> 11/2 -5R1 -> 5/2 = 2R1 -> 2/2 - 1 RO > 1/2 = 0R1, 1+1+1+0+1 -> sum of digits is 4 As seen above the base that represents 23 with the greatest sum of digits is 8 and the least sum of digits is base 2. Once the sum of digits has been displayed for each base, the program should indicate which base representation has the greatest sum of digits and which base representation has the least sum of digits. In the case where more than one base representation is tied for greatest sum of digits, indicate the highest base for the greatest sum (base 10 opposed to base 8 or base 2). When multiple base representations tie for the least sum of digits, indicate the lowest base for the least sum (base 2 opposed to base 8 or base 10). For example with the number the greatest sum of digits is 5 in bases 10, 9, 8, 7, and 6, so 10 should be indicated. On the other hand, with the 12 the least sum of digits is 2 in bases 6, 3, and 2 so 2 should be indicated. Finally the program should ask the user if they want to input another number. If they do, the program should repeat the process from the beginning with inputting a new number from the user and performing the same set of calculations to generate the correct result (previous numbers entered should have no effect on the current calculations) 3. Notes about scanf When using scanf to read in a char value (for example when asking the user to enter y or 'N'), please use the following format string:" 6" The first space before the Kc is very important it ignores the newline when you press enter after you type the previous input. Your program will not work correctly without it! Additionally if the user types "Yes", %c will read 'Y' leaving "es " in the input buffer. Having non-digit characters in the input buffer when using %d with scanf() will result in a non-successful read which may cause the program to not function correctly when failing to check if scanf() has read successfully and/or failing to clear the input buffer before reading in a number with scanf() using %d. One of the requirements of the assignment is that typing non- numeric characters at any time should not "break the program causing incorrect results and/or an infinite loop. 4. Hand-in Instructions Your file should be named asg01.tar.gz and include files Makefile, main.c to be submitted via handin.cs.clemson.edu by 11:59:59 PM of the due date. In the header comment of your main.c file, you need to also include the following things: 1. a brief description of the program 2. a guess as to how long you thought it would take to code this assignment before you got started 3. the actual time it took to code this assignment The source code will be evaluated not only on its correctness, but also on its adherence to the coding style standards "Code Formatting Requirements" provided on Canvas. Don't forget to use meaningful variable names, and don't forget about indentation, comments, and lines not exceeding 80 characters (including spaces). 5. Notes on Collaboration You are required to work individually on this assignment. Please do not consult anyone other than your instructors or the lab assistants on any aspect of this assignment. Other tutors that are available may be able to help with more general C concepts that you may be struggling with, but not with questions specific to the assignment 6. Grading Rubric 80% functionality (program works correctly and formatting of output matches) 10% formatting of code (header comment + other comments, indentation, meaningful variable names, lines not longer than 80 characters) 5% handles invalid input (should check if scanf() returns 0 and discard invalid input (walt until a non-negative number is entered, entering a letter for a number, as well as handling extra non-digit input when entering a number) 2.5% contents of header comment (name, date; description; estimation of time to code; actual time it took to code) & file named correctly 2.5% no warnings when compiled The highest possible score for a program that does not compile is 20% 7. Sample Output The following is a sample run where user input is denoted in italics. Your statements to the user don't have to be exactly what I have below, as long as they are something that is informative to the user as to what is needed and what is going on This program will take a number (in decimal) and calculate the sum of digits in base 10 down through base 2, displaying the sum of digits for each base and which base representations have the greatest and least digit sum for the given number Enter an integer (non-negative): 5 Sum of digits : Base 10: Base 9: Base 8: Base 7: Base 61 Base 5: Base 4: Base 3: Base 23 5 5 5 5 5 1 2 3 2 5 has the greatest sum of digits in base 10 and the least sum of digits in base 5 Input another number? Y/N: Y Enter an integer (non-negative): 12 Sum of digits: Base 101 3 Base 4 Base B. 5 Base 71 Base 61 2 Base 5: 4 Base 4. 3 Base 3: 2 Base 2: 2 NO 12 has the greatest sum of digits in base 7 and the least sum of digits in base 2 Input another number? Y/N: Y Enter an integer (non-negative): 250 Sum of digitsi Base 10: 7 Base 91 10 Base 12 Base 10 Base 10 Base 51 2 4: 10 Bane 31 4 Base 2: 6 250 has the greatest sum of digits in base 8 and the least sum of digits in base 5 Input another number? Y/N: Y Enter an integer (non-negative): 1000 Sum of digits: Base 10: 1 Base 9: 8 Base 8: 13 Base 7: 16 Base 6: 15 Base 5: 4 Base 4: 10 Base 3: 4 Base 6 21 1000 has the greatest sum of digits in base 7 and the least sum of digits in base 10 Input another number? Y/N: Enter an integer (non-negative): 3456 Sum of digits : Base 10: 18 Base 9: 16 Base 8: 12 Base 70 12 61 6 Base 5: 8 Base 4: 6 Base 3: 6 Base 2: 4 Base 3456 has the greatest sum of digits in base 10 and the least sum of digits in base 2 Input another number? Y/N: Y Enter an integer (non-negative): 65535 Sum of digitsi Rase 10: 24 Base 9: 23 Base 8: 36 7: 15 Base 6: 15 Base 5: 15 Bane 41 24 Base 3: 11 Base 2: 16 65535 has the greatest sum of digits in base 8 and the least sum of digits in base 3 Input another number? Y/ NN CPSC 1110 Fall 2020, Programming Assignment 1: Sum of Digits Due 11:59:59 pm on due date 1. Overview The purpose of this assignment is to give you some experience using loops & conditionals, as well as printf & scanf, declaring variables, and using logical expressions. 2. More Assignment Specifics This program will prompt the user to enter in a non-negative integer in decimal (base 10). The sum of digits of the number value entered will be calculated starting with base 10 representation (as the number was typed down through base 2 (binary) representation and the sum of digits of the number in each base representation will be displayed. The number value itself does not need to be displayed in any other base representation As an example given the number input as 23 Base 10:23/10 = 23 -> 2/10 = OR2 (end with O), add remainders 342->sum of digits is 5 Base 9: 23/9 - 2RS -> 2/9 - 0R2, 5+2 -> sum of digits is 7 Base 8: 23/8 - 2R7 -> 2/8 = OR2, 7+2 -> sum of digits is 9 Base 7: 23/7 = 3R2 -> 3/ 70R3, 2+3 -> sum of digits iss Base 6: 23/6 = 3R5 -> 3/6=0R3, 5+3 -> sum of digits is 8 Base 5: 23/5 = 4R3 -> 4/5 = 0R4, 3 + 4 -> sum of digits is 7 Base 4: 23/4 = 5R3 -> 5/4 = 1R1 -> 1/4 = 0R1, 3+1+1 -> sum of digits is 5 Base 3: 23/3 = 7R2-> 7/3 = 2R1 -> 2/3=0R2,2 +1 +2 -> sum of digits is 5 Base 2: 23/2 = 11R1 -> 11/2 = 5R1 -> 5/2 = 2R1 -> 2/2 = 1R0 -> 12 = 0R1, 1+1+1+0+1>sum of digits is 4 As seen above the base that represents 23 with the greatest sum of digits is 8 and the least sum of digits is base 2. Once the sum of digits has been displayed for each base, the program should indicate which base representation has the greatest sum of digits and which base representation has the least sum of digits. In the case where more than one base representation is tied for greatest sum of digits, indicate the highest base for the greatest sum (base 10 opposed to base 8 or base 2). When multiple base representations tie for the least sum of digits, indicate the lowest base for the least sum (base 2 opposed to base 8 or base 10). For example with the number 5 the greatest sum of digits is 5 in bases 10, 9, 8, 7, and 6, so 10 should be indicated. On the other hand, with the 12 the least sum of digits is 2 in bases 6, 3, and 2 so 2 should be indicated. Finally the program should ask the user if they want to input another number. If they do, the program should repeat the process from the beginning with inputting a new number from the user and performing the same set of calculations to generate the correct result (previous numbers entered should have no effect on the current calculations). 3. Notes about scanf When using scanf to read in a char value (for example when asking the user to enter 'Y' or 'N'), please use the following format string: 10" The first space before the %c is very important! it ignores the newline when you press enter after you type the previous input. Your program will not work correctly without it! Additionally if the user types "Yes", %c will read "Y" leaving "es " in the input buffer. Having non-digit characters in the input buffer when using %d with scanf() will result in a non-successful read which may cause the program to not function correctly when failing to check if scanf() has read successfully and/or failing to clear the input buffer before reading in a number with scanf() using %d. One of the requirements of the assignment is that typing non- numeric characters at any time should not "break the program causing incorrect results and/or an infinite loop. 4. Hand-in Instructions Your file should be named asg01.tar.gz and include files Makefile, main.c to be submitted via handin.cs.clemson.edu by 11:59:59 PM of the due date. In the header comment of your main.c file, you need to also include the following things: 1 a brief description of the program 2. a guess as to how long you thought it would take to code this assignment before you got started 3. the actual time it took to code this assignment The source code will be evaluated not only on its correctness, but also on its adherence to the coding style standards "Code Formatting Requirements" provided on Canvas. Don't forget to use meaningful variable names, and don't forget about indentation, comments, and lines not exceeding 80 characters (including spaces). 5. Notes on Collaboration You are required to work individually on this assignment. Please do not consult anyone other than your instructors or the lab assistants on any aspect of this assignment. Other tutors that are available may be able to help with more general C concepts that you may be struggling with, but not with questions specific to the assignment 80% 6. Grading Rubric functionality (program works correctly and formatting of output matches) 10% formatting of code (header comment + other comments, indentation, meaningful variable names, lines not longer than 80 characters) 5% handles invalid input (should check if scanf() returns O and discard invalid input (wait until a non-negative number is entered, entering a letter for a number, as well as handling extra non-digit input when entering a number) 2.5% contents of header comment (name; date; description; estimation of time to code; actual time it took to code) & file named correctly no warnings when compiled 2.5% The highest possible score for a program that does not compile is 20% 7. Sample Output The following is a sample run where user input is denoted in italics. Your statements to the user don't have to be exactly what I have below, as long as they are something that is informative to the user as to what is needed and what is going on = - This program will take a number (in decimal) and calculate the sum of digits in base 10 down through base 2, displaying the sum of digits for each base and which base representations have the greatest and least digit sum for the given number Enter an integer (non-negative): 5 Sum of digits: Base 10: 5 Base 9: 5 Base 8: 5 Base 7: 5 Base 6: 5 Base 5: 1 Base 4: 2 Base 3: 3 Base 2: 2 5 has the greatest sum of digits in base 10 and the least sum of digits in base 5 Input another number? Y/N: Y Enter an integer (non-negative): 12 Sum of digits: Base 10: Base 9: Base 8: Base 7: Base 6: Base 5: Base 4: Base 3: Base 3 4 5 6 2 4 3 2 2 2: 12 has the greatest sum of digits in base 7 and the least sum of digits in base 2 Input another number? Y/N: Y Enter an integer (non-negative): 250 Sum of digits: Base 10: 7 Base 9: 10 Base 8: 12 Base 7: 10 Base 6: 10 Base 5: 2 Base 4: 10 Base 3: 4 Base 2: 6 250 has the greatest sum of digits in base 8 and the least sum of digits in base 5 Input another number? Y/N: Y Enter an integer (non-negative): 1000 Sum of digits: Base 10: 1 Base 9: 8 Base 13 Base 16 Base 15 Base Base 4: 10 Base 3: 4 Base 2: 6 8: 7: 6: 5: 4 1000 has the greatest sum of digits in base 7 and the least sum of digits in base 10 Input another number? Y/N: Y Enter an integer (non-negative): 3456 Sum of digits: Base 10: 18 Base 9: 16 Base 8: 12 Base 7: 12 Base 6: 6 Base 5: 8 Base 6 Base 3: 6 Base 2: 4 3456 has the greatest sum of digits in base 10 and the least sum of digits in base 2 Input another number? Y/N: Y Enter an integer (non-negative): 65535 Sum of digits: Base 10: 24 Base 9: 23 Base 8: 36 Base 7: 15 Base 6: 15 Base 5: 15 Base 24 Base 3: 11 Base 2: 16 65535 has the greatest sum of digits in base 8 and the least sum of digits in base 3 Input another number? Y/N: N

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!