<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # C++ 程序:計算兩個時間段之間的差異 > 原文: [https://www.programiz.com/cpp-programming/examples/time-structure](https://www.programiz.com/cpp-programming/examples/time-structure) 要理解此示例,您應該了解以下 [C++ 編程](/cpp-programming "C++ tutorial")主題: * [C++ 結構](/cpp-programming/structure) * [C++ 結構和函數](/cpp-programming/structure-function) * [C++ 指向結構的指針](/cpp-programming/structure-pointer) * * * * * * ## 示例:程序與時間差異 ```cpp // Computes time difference of two time period // Time periods are entered by the user #include <iostream> using namespace std; struct TIME { int seconds; int minutes; int hours; }; void computeTimeDifference(struct TIME, struct TIME, struct TIME *); int main() { struct TIME t1, t2, difference; cout << "Enter start time." << endl; cout << "Enter hours, minutes and seconds respectively: "; cin >> t1.hours >> t1.minutes >> t1.seconds; cout << "Enter stop time." << endl; cout << "Enter hours, minutes and seconds respectively: "; cin >> t2.hours >> t2.minutes >> t2.seconds; computeTimeDifference(t1, t2, &difference); cout << endl << "TIME DIFFERENCE: " << t1.hours << ":" << t1.minutes << ":" << t1.seconds; cout << " - " << t2.hours << ":" << t2.minutes << ":" << t2.seconds; cout << " = " << difference.hours << ":" << difference.minutes << ":" << difference.seconds; return 0; } void computeTimeDifference(struct TIME t1, struct TIME t2, struct TIME *difference){ if(t2.seconds > t1.seconds) { --t1.minutes; t1.seconds += 60; } difference->seconds = t1.seconds - t2.seconds; if(t2.minutes > t1.minutes) { --t1.hours; t1.minutes += 60; } difference->minutes = t1.minutes-t2.minutes; difference->hours = t1.hours-t2.hours; } ``` **輸出** ```cpp Enter hours, minutes and seconds respectively: 11 33 52 Enter stop time. Enter hours, minutes and seconds respectively: 8 12 15 TIME DIFFERENCE: 11:33:52 - 8:12:15 = 3:21:37 ``` 在該程序中,要求用戶輸入兩個時間段,這兩個時間段分別存儲在結構變量`t1`和`t2`中。 然后,`computeTimeDifference()`函數計算時間段之間的時差,結果從`main()`函數顯示在屏幕上,而不會返回(通過引用調用)。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看