SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 07 Jan 2018 My Price 8.00

code fragment below, what does it print when the user

c++ programing 

 

1) Given the code fragment below, what does it print when the user enters 2 and then 3?

Could you explain why the result is not 5?

    // 0 to 9

    char digit1, digit2;

    cout<<"Enter a digit: ";

    cin>> digit1;

    cout<<"Enter another digit: ";

    cin>> digit2;

    cout<<"Sum of "<<digit1<<" + "<<digit2<<" is "<<(digit1 + digit2)<<endl;

 

2) Same as the question above but the code has been modified slightly. What is the output now when the user enters 2 and then 3?

    // 0 to 9

    string digit1, digit2;

    cout<<"Enter a digit: ";

    cin>> digit1;

    cout<<"Enter another digit: ";

    cin>> digit2;

    cout<<"Sum of "<<digit1<<" + "<<digit2<<" is "<<(digit1 + digit2)<<endl;

 

3) Same as the question above but the code has been modified slightly. What is the output now when the user enters 2 and then 3?

    // 0 to 9

    int digit1, digit2;

    cout<<"Enter a digit: ";

    cin>> digit1;

    cout<<"Enter another digit: ";

    cin>> digit2;

    cout<<"Sum of "<<digit1<<" + "<<digit2<<" is "<<(digit1 + digit2)<<endl;

 

4) From the examples above, when a user types a value like 2 or 3 as input, is that value a number, a character, or a string?

What determines what the program will treat the value as?

 

5) Same as question 3 but the user now enters "two" when asked for the first digit. What does the program print?

    // 0 to 9

    int digit1, digit2;

    cout<<"Enter a digit: ";

    cin>> digit1;

    cout<<"Enter another digit: ";

    cin>> digit2;

    cout<<"Sum of "<<digit1<<" + "<<digit2<<" is "<<(digit1 + digit2)<<endl;

 

6) Same as question 1 but the user now enters "two" when asked for the first digit. What does the program print?

    // 0 to 9

    char digit1, digit2;

    cout<<"Enter a digit: ";

    cin>> digit1;

    cout<<"Enter another digit: ";

    cin>> digit2;

    cout<<"Sum of "<<digit1<<" + "<<digit2<<" is "<<(digit1 + digit2)<<endl;

 

7) Given the code fragment below, what does it print when the user enters John Smith? Please briefly explain why this happens.

    string name;

    cout<<"Enter name: ";

    cin>> name;

    cout<<"Hello "<<name<<endl;

 

8) Please briefly explain (~3 lines) how reading from a file is similar to reading from cin and writing to a file is similar to writing to cout.

 

9) Give an example (~2 lines) of when you may want to read a file character by character as opposed to word by word. Give an example (~2 lines) when it would be more appropriate to read the file word by word.

 

10) Give a code fragment that attempts to open a file "myFile.txt" and terminates the program if the file was not opened successfully.

Answers

(5)
Status NEW Posted 07 Jan 2018 12:01 PM My Price 8.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)