最基础的C++代写， 使用cygwin入门写一个Hello World程序来入门格式化输入输出。
In this lab, you will learn how to use the cygwin/gcc environment to write, compile, and run C programs.
(1) First, start the cygwin bash shell. This is available from the Start menu on all of the computers in the KEC building. The full path in the menu is:
Start->All Programs->Cygwin->Cygwin Terminal
Once the cygwin bash shell has started, type the following commands, pressing the Enter key after each command:
The first command navigates to your H: drive. The second command creates a directory in your H: drive called CS101. The third command navigates into the newly-created CS101 directory.
(2) Using a web browser, download CS101_Lab01.zip. Save the zip file in the H:\CS101 directory.
(3) From the Cygwin bash shell, run the following command:
When you run this command, you should see output looking something like the following:
(4) Navigate into the CS101_Lab01 directory containing the lab files:
(5) Start the Notepad++ text editor. This is available from the Start menu:
Once Notepad++ has started, choose File->Open from the menu, and open the file
Your task is to add a main function to the hello.cpp file to accomplish the following tasks:
- Print the message Hello, CS 101! to the output window
- Prompt the user for their age in years. Store the value entered by the user in an int variable.
- Print the message OK, you are N years old, where N is the integer value entered by the user.
Here is an example run (user input in bold):
Hello, CS 101!
To compile the program (run the compiler to translate your C source code into an executable file), run the following command using the Cygwin bash shell:
If the compilation is successful, you should see something like the following output:
g++ -g -Wall -c -o hello.o hello.cpp
If you see a compiler error message, ask the instructor or lab coach for help.
Once the program is compiled, run the program by typing the following command in the Cygwin bash shell:
- Put #include <stdio.h> at the top of hello.cpp. This will allow your progam to use the printf and scanf functions.
- Use the printf function to print output to the screen.
- Declare an int variable to store the user’s age.
- Use the scanf function to read the user’s age.
When you are done, run the following command from the Cygwin bash shell:
You will be prompted for your Marmoset username and password, which you should have received by email. The entire submission process should produce output that looks something like the following:
Creating submit.properties file
You will use your own username in place of “jstudent”. Note that when you type your password, it will not be echoed to the screen.
You must submit your work before leaving class. If you do not submit, you will not receive any credit for the lab.