TAILIEUCHUNG - C++ Lab 3 Branching

When instructions within a program are executed one after the other sequentially that program is said to have a linear structure. Decision making after examining all available options is very important in life as well as in programming. For example, it is the law that all males 18 or older should register with the selective service. If you are writing a program to send out reminders to enforce this law, the decision to send the letter should be based on if a person is male and if he is 18 or older. In this chapter you will learn how to. | Lab 3 Branching When instructions within a program are executed one after the other sequentially that program is said to have a linear structure. Decision making after examining all available options is very important in life as well as in programming. For example it is the law that all males 18 or older should register with the selective service. If you are writing a program to send out reminders to enforce this law the decision to send the letter should be based on if a person is male and if he is 18 or older. In this chapter you will learn how to write statements that make decisions. A simple program to look at an average grade of a student and display if that student passed or failed would look like this Program 3-1 There are several enhancements to this program. I added include iomanip which allows the output to be formatted. There are several stream manipulators in the iomanip . I used setw fixed showpoint and setprecission manipulators to give field width fixed-point notation rather than scientific notation decimal point and significant digits respectively. I also used before the getchar . The will clear the keyboard buffer of the newline character. Program 3-1. Accept three grades find the average and display Passed or Failed. Teach objective - making decisions By Dr. John Abraham Created for 1380 students include iostream include iomanip to format input and output. Here setw and endl require it include fstream using namespace std void printToFile int int int double int main int one two three double average cout Enter three grades cin one two three average one two three the total of three grades are first converted float cout Three grades are one setw 4 two setw 4 three endl endl inserts line feed and carriage return cout fixed showpoint setprecision 2 What does this line do cout The average is average endl if average 70 cout Student passed the course .

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.