write a small application that creates the complete command string that would be
ID: 3883112 • Letter: W
Question
write a small application that creates the complete command string that would be sent to the OUSB Board to increment the LEDs sequentially from 0 to 10 and display it on the console window. Note that you will also need to consider the function _itoa_s()
Another common task is to compare two nullterminated strings to confirm that they are identical.
Unlike numerical data, the equivalence (‘==’) operator cannot be used. To compare nullterminated strings the function strcmp() can be utilised.
Set the command line input argument to the letter 'a' and write a small program using strcmp() to determine if the character is indeed an 'a'.
To create the nullterminated string to compare against you can use the following code: const char letterA[2] = {'a',''}; or const char letterB[] = "b";
Explanation / Answer
import java.io.InputStream; import java.util.Scanner; public class TranscriptReader { private final Scanner scanner; public TranscriptReader(InputStream in) { this.scanner = new Scanner(in); } public Transcript readTranscript() { Transcript transcript = new Transcript(); int lineNumber = 1; while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); if (line.equals("end")) { break; } if (line.isEmpty()) { lineNumber++; continue; } if (parts.length != 2) { System.err.println( "Line " + lineNumber + " contains invalid number of " + "tokens (" + parts.length + "). Should have exactly " + "two: number of credits and the grade."); lineNumber++; continue; } String creditsString = parts[0]; String gradeString = parts[1]; int credits; int grade; try { credits = Integer.parseInt(creditsString); } catch (NumberFormatException ex) { System.err.println( "Invalid credit token on line " + lineNumber + ": " + creditsString); ++lineNumber; continue; } try { grade = Integer.parseInt(gradeString); } catch (NumberFormatException ex) { System.err.println( "Invalid grade token on line " + lineNumber + ": "+ gradeString); ++lineNumber; continue; } transcript.addCourse(new Course(credits, grade)); lineNumber++; } scanner.close(); return transcript; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.