C++代写:入门格式化输入输出

最基础的C++代写, 使用cygwin入门写一个Hello World程序来入门格式化输入输出。

YCP Logo CS 101 - Lab 1: Hello, CS 101

In this lab, you will learn how to use the cygwin/gcc environment to write, compile, and run C programs.

Getting Started

(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:

1
2
3
cd h:
mkdir -p CS101
cd CS101

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:

1
unzip CS101_Lab01.zip

When you run this command, you should see output looking something like the following:

1
2
3
4
Archive:  CS101_Lab01.zip
extracting: CS101_Lab01/hello.cpp
inflating: CS101_Lab01/Makefile
inflating: CS101_Lab01/submitToMarmoset.pl

(4) Navigate into the CS101_Lab01 directory containing the lab files:

1
cd CS101_Lab01

(5) Start the Notepad++ text editor. This is available from the Start menu:

Start->All Programs->Notepad++->Notepad++

Once Notepad++ has started, choose File->Open from the menu, and open the file

H:\CS101\CS101_Lab01\hello.cpp

Your Task

Your task is to add a main function to the hello.cpp file to accomplish the following tasks:

  1. Print the message Hello, CS 101! to the output window
  2. Prompt the user for their age in years. Store the value entered by the user in an int variable.
  3. 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):

1
2
3
Hello, CS 101!
How old are you? 36
OK, you are 36 years old

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:

1
make

If the compilation is successful, you should see something like the following output:

1
2
g++ -g -Wall   -c -o hello.o hello.cpp
g++ -o hello.exe hello.o

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:

1
./hello.exe

Hints

  • 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.

Submitting

When you are done, run the following command from the Cygwin bash shell:

1
make submit

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Creating submit.properties file
Collecting the names of files to be submitted
Creating a solution zip file
adding: hello.cpp (deflated 7%)
adding: Makefile (deflated 54%)
adding: submitToMarmoset.pl (deflated 61%)
./submitToMarmoset.pl solution.zip submit.properties
Enter your username: jstudent
Enter your password:
Successful submission #3 received for project lab1
######################################################################
>>>>>>>> Successful submission! <<<<<<<<<

Make sure that you log into the marmoset server to manually
check that the files you submitted are correct.

Details:

Semester: Spring 2010
Course: CS 101
Assignment: lab01

######################################################################

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.

Important:

You must submit your work before leaving class. If you do not submit, you will not receive any credit for the lab.

kamisama wechat
KamiSama