THÔNG TIN TÀI LIỆU
TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI KỸ THUẬT LẬP TRÌNH HỆ CƠ ĐIỆN TỬ Programming for Mechatronic Systems Giảng viên: TS Nguyễn Thành Hùng Đơn vị: Bộ môn Cơ điện tử, Viện Cơ khí Hà Nội, 2020 Chapter I Basics and data management of C++ ❖ Creation of C++ programs ❖ Basic data types, variables and constants ❖ Basic operations and expressions ❖ Control program structures ❖ Exception handling ❖ Pointers, references and dynamic memory management ❖ Arrays and strings ❖ User-defined data types Creation of C++ programs ❖ Some important rules ▪ The basic elements of the program: the characters of the bit ASCII code table ▪ Character and text constants, as well as remarks may contain characters of any coding Creation of C++ programs ❖ Some important rules ▪ C++ compiler differentiates small and capital letters in the words (names) used in the program ▪ Certain (English) words cannot be used as own names since these are keywords of the compiler ▪ In case of creating own names please note that they have to start with a letter (or underscore sign), and should contain letters, numbers or underscore signs in their other positions Creation of C++ programs ❖ The first C++ program in two versions // Circle1.cpp #include "cstdio" #include "cmath" using namespace std; C int main() { const double pi = 3.14159265359; double radius, area, perimeter; // Reading radius printf("Radius = "); scanf("%lf", &radius); // Calculations perimeter = * radius*pi; area = pow(radius, 2)*pi; printf("Perimeter: %7.3f\n", perimeter); printf("Area: %7.3f\n", area); // Waiting for pressing Enter getchar(); getchar(); return 0; } // Circle2.cpp #include "iostream" #include "cmath" using namespace std; C++ int main() { const double pi = 3.14159265359; // Reading radius double radius; cout > radius; // Calculations double perimeter = * radius*pi; double area = pow(radius, 2)*pi; cout
Ngày đăng: 15/02/2022, 19:02
Xem thêm: