Академический Документы
Профессиональный Документы
Культура Документы
Topics
Output
cout
Description
Write a program that will display the following
three-line message five times. After printing the
three-line message, print an empty line before
printing the three-line message again.
Requirements
Print the above message five times each time using a
different method. The different methods to be used
are listed below. For an example of the use of these
five methods, see the sample code in the Sample
Code section below.
Submit
A copy of the output.
A copy of the source code.
Hi1
Hi2
Hi3
#include< iostream>
#include< string>
using namespace std;
int main ( )
{
//method 1
cout << "Hi1" << endl;
cout << "Hi2" << endl;
cout << "Hi3" << endl << endl;
//method 2
cout << "Hi1\n";
cout << "Hi2\n";
cout << "Hi3\n\n";
//method 3
cout << "Hi1" << endl
<< "Hi2" << endl
<< "Hi3" << endl << endl;
//method 4
cout << "Hi1\nHi2\n"
<< "Hi3\n\n";
//method 5
string out;
out = "Hi1\n";
out = out + "Hi2\n";
out = out + "Hi3\n\n";
cout << out;
return 0;
}
Assignment 2
Topics
input
output
Description
Write a program that will input some of user's personal information and then display it back to
the user.
First, the program will ask the user to enter name. Then it will ask the user to enter address. Then
it will ask the user to enter phone number. Then it will ask the user to enter email. At the end, it
will display the user’s name, address, phone number and email. See the Testing section below.
Testing
Test Run
(User input is shown in bold).
Enter Name:
John Doe
Enter Address:
321 Golf Club Road, Pleasant Hill, CA 94523
Enter Phone Number:
925-685-1230
Enter Email:
jdoe@dvc.edu
User Information:
Name: John Doe
Address: 321 Golf Club Road, Pleasant Hill, CA 94523
Phone: 925-685-1230
Email: jdoe@dvc.edu
Submit
Sample Code
/*
The sample code below inputs user's name and address and then displays it back to the user
under the title Personal Information.
*/
//Input name
cout << "Enter Name:" << endl;
getline (cin, name);
//Input address
cout << "Enter Address:" << endl;
getline (cin, addr);
//Display output;
cout << "Personal Information" << endl;
cout << "Name: " << name << endl;
cout << "Address: " << addr << endl;
Assignment 3
Topics
Inputting numeric data
Outputing numeric data
Assignment statement
Expressions
Evaluating an expression
Description
Write a program that computes the sum and the average of any three decimal numbers provided
by the user.
The program asks the user to input three decimal numbers one at a time. It will compute the sum
and the average of the three numbers. Then it will display the three numbers and their sum in one
line and the three numbers and their average in a second line. See the Test Run in the Testing
section.
Testing
Use the test data in Test Run below:
Test Run
(User input is shown in bold).
Submit
The final two-line output
The source code
Sample Code
//Input numbers
cout << "Enter the first number" << endl;
cin >> n1;
cout << "Enter the second number" << endl;
cin >> n2;
cout << "Enter the third number" << endl;
cin >> n3;
//compute the sum of the numbers and save it in the variable sum
sum=n1+n2+n3;