"C + + Primer plus English version Sixth edition" Chapter 2

Source: Internet
Author: User

Chapter Review
  1. They is called functions.
  1. It causes the contents of the file to being substituted for this iostream directive before final compilation.
  1. It makes definitions made in the std namespace available to a program.
  1. cout << "Hello, world" << endl;Orcout << "Hello, world\n";
  1. int cheeses;
  1. cheeses = 32;
  1. cin >> cheeses;
  1. cout << "We have " << cheeses << " varieties of cheese\n";
  1. The function froop() expects to is called with one argument, which'll be double is type, and that the function would return a T Ype int value. For instance, it could is used as follows:
    int gval = froop(3.14159);
    The function has a rattle() no return value and expects an int argument. For instance, it could is used as follows:
    rattle(37);
    The function returns an and expects to is prune() int used without an argument. For instance, it could is used as follows:
    int residue = prune();
  1. You do not have the-use return -a function when the function has the return type void . However, you can use it if you don ' t give a return value:
    return;
  1. The likely cause it, the function loses a statement to using namespace std; declare a directive of output.
    Place using namespace std; above the main() function;
    Place in the using std::cout; main() function;
    Type as following:using std::cout << "Please enter your PIN: " << std::endl;
Programming Exercises1
#include <iostream>int main(){    usingnamespace std;        "Name: NaRiSu;\n"         "Address: BeiJing;" << endl;             return0;}
2
#include <iostream>int main(){    usingnamespace std;        int furlong;    cin >> furlong;    " furlong(s) = "         220" yard(s)" << endl;        return0;}
3
#include <iostream>void f1();void f2();usingnamespace std;int main(){       f1();    f1();    f2();    f2();        return0;}void f1(){    "Three blind mice" << endl;}void f2(){    "See how they run\n"// 也可以用f1()函数中的endl形式。        return// void f2()表明无返回值,故可以这样写;也可以如f1()不写return语句。}
4
#include <iostream>int main(){    usingnamespace std;        "Enter your age: ";    int age;    cin >> age;    "Your age in months is "12"." << endl;        return0;}
5
#include <iostream>double fahrenheit(double);int main(){    usingnamespace std;        "Please enter a Celsius value: ";    int celsius;    cin >> celsius;    " degrees Celsius is "         " degrees Fahrenheit." << endl;        return0;}double fahrenheit(double n){    return1.832.0;}
6
#include <iostream>double astronomical(double);int main(){    usingnamespace std;        "Enter the number of light years: ";    double light;    cin >> light;    " light years = "         " astronomical units." << endl;        return0;}double astronomical(double n){    return63240 * n;}
7
 #include <iostream>  void  F (int , int );        int  Main () {using  namespace  std;    cout <<  "Enter the number of Hours:" ;    int  hour;    CIN >> Hour;    cout <<  "Enter the number of minutes:" ;    int  minute;    CIN >> minute;        F (hour, minute); return  0 ;} void  F (int  H, int  m) {        Using  namespace  std; cout <<  "time:"  << H <<  << m << Endl; }

C + + Primer plus the sixth edition of the English version Chapter 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.