' ' Submarine data analysis ' John Dalbey 1/22/99 ' Abstract: ' INPUT engineering data gathered from testing a submarine. ' Each data set contains sample number, speed, depth, and vibration. ' Issue a warning if a sample has speed > 15 knots and ' depth > 750 feet. Count how many warnings are issued. '
' set count to zero Warnings = 0
' Input sample number INPUT "Sample: ", Number ' Loop to read all sets of data WHILE Number <> 9999
' INPUT the measurements INPUT "Readings: ", Speed, Depth, Vibration ' Check if measures deserve a warning IF (Speed > 15 AND Depth > 750) THEN ' Output warning and sample and vibration PRINT "Warning! " PRINT Number, PRINT Vibration PRINT ' Increment counter Warnings = Warnings + 1 END IF ' read next sample INPUT "Sample: ", Number WEND ' Print a row of stars FOR StarCount = 1 TO 50 PRINT "*"; NEXT StarCount PRINT ' Display the count PRINT "There were "; PRINT Warnings; PRINT " warnings issued during this run." PRINT END
|
* * Submarine data analysis * John Dalbey 1/22/99 * Abstract: * Read engineering data gathered from testing a submarine. * Each data set contains sample number, speed, depth, and vibration. * Issue a warning if a sample has speed > 15 knots and * depth > 750 feet. Count how many warnings are issued. * PROGRAM Submarine ! Variable declarations INTEGER Number, Speed, Depth, Warnings, StarCount REAL Vibration
* set count to zero Warnings = 0 * Input sample number PRINT *, 'Sample: ' Read *, Number * Loop to read all sets of data DO IF (Number .EQ. 9999) EXIT ! Read the measurements PRINT *, 'Readings: ' Read *, Speed, Depth, Vibration
* Check if measures deserve a warning IF (Speed > 15 .AND. Depth > 750) THEN * Output warning and sample and vibration PRINT *, 'Warning! ', Number, Vibration PRINT *
* Increment counter Warnings = Warnings + 1 ENDIF * Read next sample PRINT *, 'Sample: ' Read *, Number ENDDO * Print a row of stars DO StarCount = 1, 50 WRITE(*, '(A1)', ADVANCE="NO") '*' ENDDO PRINT * * Display the count PRINT *, 'There were ' PRINT *, Warnings PRINT *, ' warnings issued during this run. ' PRINT *
END
|
{ Submarine data analysis John Dalbey 1/22/99 Abstract: Read engineering data gathered from testing a submarine. Each data set contains sample number, speed, depth, and vibration. Issue a warning if a sample has speed > 15 knots and depth > 750 feet. Count how many warnings are issued. }
PROGRAM Submarine; { Variable declarations } VAR Number : INTEGER; { sample number } Speed : INTEGER; { submarine speed } Depth : INTEGER; { distance below surface } Vibration : REAL; { vibration measurement } Warnings : INTEGER; { how many warnings } StarCount : INTEGER; { count number stars printed } BEGIN Warnings := 0; { set count to zero } { Input sample number } Write ('Sample: '); Read (Number); { Loop to read all sets of data } WHILE Number <> 9999 DO BEGIN { Read the measurements } Write ('Readings: '); Read (Speed); Read (Depth); Read (Vibration); { Check if measures deserve a warning } IF (Speed > 15) AND (Depth > 750) THEN BEGIN { Output warning and sample and vibration } Write ('Warning! '); Write (Number:1,' '); Write (Vibration:5:2); Writeln; { Increment counter } Warnings := Warnings + 1; END; { Read next sample } Write ('Sample: '); Read (Number); END; { Print a row of stars } FOR StarCount := 1 TO 50 DO BEGIN Write ('*'); END; Writeln; { Display the count } Write ('There were '); Write (Warnings:1); Write (' warnings issued during this run.'); Writeln; END.
|
-- -- Submarine data analysis -- John Dalbey 1/22/99 -- Abstract: -- Read engineering data gathered from testing a submarine. -- Each data set contains sample number, speed, depth, and vibration. -- Issue a warning if a sample has speed > 15 knots and -- depth > 750 feet. Count how many warnings are issued. WITH Text_IO, My_Int_IO, My_Flt_IO; USE Text_IO, My_Int_IO, My_Flt_IO; PROCEDURE Submarine IS -- Variable declarations -- (Note: numeric ranges were given in the problem statement) Number : INTEGER RANGE 1 .. 9999; -- sample number Speed : INTEGER RANGE 1 .. 45; -- submarine speed Depth : INTEGER RANGE 0 .. 5500; -- distance below surface Vibration : FLOAT RANGE 0.0 .. 100.0; -- vibration measurement Warnings : INTEGER RANGE 0 .. 9999; -- how many warnings
BEGIN Warnings := 0; -- set count to zero -- Input sample number Put ("Sample: "); Get (Number); -- Loop to read all sets of data WHILE Number /= 9999 LOOP -- Read the measurements Put ("Readings: "); Get (Speed); Get (Depth); Get (Vibration); -- Check if measures deserve a warning IF Speed > 15 AND Depth > 750 THEN -- Output warning and sample and vibration Put ("Warning! "); Put (Number, WIDTH=>1); Put (Vibration, Fore=>5, Aft=>2, Exp=>0); New_Line; -- Increment counter Warnings := Warnings + 1; END IF; -- Read next sample Put ("Sample: "); Get (Number); END LOOP; -- Print a row of stars FOR StarCount IN 1 .. 50 LOOP Put ('*'); END LOOP; New_Line; -- Display the count Put ("There were "); Put (Warnings, WIDTH=>1); Put (" warnings issued during this run."); New_Line;
END Submarine;
|
// // Submarine data analysis // John Dalbey 1/22/99 // // Read engineering data gathered from testing a submarine. // Each data set contains sample number, speed, depth, and vibration. // Issue a warning if a sample has speed > 15 knots and // depth > 750 feet. Count how many warnings are issued. #include <iostream.h> #include <iomanip.h> int main () {
// Variable declarations int Number; // sample number int Speed; // submarine speed int Depth; // distance below surface float Vibration; // vibration measurement int Warnings; // how many warnings int StarCount; // count of stars printed
cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); cout << setprecision(2); Warnings = 0; // set count to zero
//Input sample number cout << "Sample: "; cin >> Number;
//Loop to read all sets of data while (Number != 9999) { // Read the measurements cout << "Readings: "; cin >> Speed; cin >> Depth; cin >> Vibration;
// Check if measures deserve a warning if ((Speed > 15) && (Depth > 750)) { // Output warning and sample and vibration cout << "Warning! "; cout << Number << " "; cout << Vibration; cout << endl;
// Increment counter Warnings = Warnings + 1; } // Read next sample cout << "Sample: "; cin >> Number;
}
// Print a row of starts for (StarCount=1; StarCount<=50; StarCount++) { cout << '*'; } cout << endl;
// Display the count cout << "There were "; cout << Warnings; cout << " warnings issued during this run."; cout << endl;
return 0; }
|