Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Nhân này bằng 100,0 bạn có được một giá trị giữa 0,0 và 100,0. Cho vòng lặp các cửa hàng một giá trị ngẫu nhiên trong mỗi phần tử của mảng mẫu. Một đối tượng ngẫu nhiên cũng có một (chức năng) Tiếp theo đó trả về một giá trị không âm ngẫu nhiên kiểu int. Nếu bạn cung cấp một số nguyên | Chapter 7 Try It Out Using structs Now use another console application example to exercise a little further how referencing the members of a struct works. Suppose you want to write a program to deal with some of the things you might find in a yard such as those illustrated in the professionally landscaped yard in Figure 7-1. Position 100 120 Figure 7-1 I have arbitrarily assigned the coordinates 0 0 to the top-left corner of the yard. The bottom-right corner has the coordinates 100 120. Thus the first coordinate value is a measure of the horizontal position relative to the top-left corner with values increasing from left to right and the second coordinate is a measure of the vertical position from the same reference point with values increasing from top to bottom. 326 Defining Your Own Data Types Figure 7-1 also shows the position of the pool and that of the two huts relative to the top-left corner of the yard. Because the yard huts and pool are all rectangular you could define a struct type to represent any of these objects struct RECTANGLE int Left int Top int Right int Bottom Top left point coordinate pair Bottom right point coordinate pair The first two members of the RECTANGLE structure type correspond to the coordinates of the top-left point of a rectangle and the next two to the coordinates of the bottom-right point. You can use this in an elementary example dealing with the objects in the yard as follows Ex7_01.cpp Exercising structures in the yard include iostream using std cout using std endl Definition of a struct to represent rectangles struct RECTANGLE int Left int Top Top left point coordinate pair int Right Bottom right point int Bottom coordinate pair Prototype of function to calculate the area of a rectangle long Area RECTANGLE aRect Prototype of a function to move a rectangle void MoveRect RECTANGLE aRect int x int y int main void RECTANGLE Yard 0 0 100 120 RECTANGLE Pool 30 40 70 80 RECTANGLE Hut1 Hut2 Hut1.Left 70 Hut1.Top 10 Hut1.Right .