Question

In: Computer Science

5. Write a C++ statement or statements that will:       Print the first two digits and the  last...

5. Write a C++ statement or statements that will:      

Print the first two digits and the  last two digits of any 4 digit number stored in an integer variable n.        

For example, given int n = 5623, print

56    23.

6. Write  C++ statements that will align the following three lines as printed in two 20 character columns.

Name                                                 Years President

Abraham Lincoln                                 1860-1865

Thomas Jefferson                               1801-1809

7.  Write a C++ statement or statements that will Output if a string has a length greater than 10, equal to 10 or less than 10.

Examples  :    

string str1 = “Four Score and Seven Years Ago”      would output “String Length > 10”

string str2 = “Good Day”                                            would output “String Length < 10”

string str3 = 0123456789”                                          would output “String Length = 10”

Solutions

Expert Solution

5.

Source Code:

#include <iostream>
using namespace std;

int main()
{
   int n=5623;
   cout<<(n/100)<<" "<<(n%100)<<endl;
   // modulo 100 returns last 2 digits and
   // division with 100 gives first 2 digits
}

6.

Source Code:

#include <iostream>
using namespace std;

int main()
{
   cout<<"Name"<<" "<<"Years President"<<endl;
   cout<<"Abraham Lincoln"<<" "<<"1860-1865"<<endl;
   cout<<"Thomas Jefferson"<<" "<<"1801-1809"<<endl;
}

7.

Source Code:

#include <iostream>
using namespace std;
void sayStringLength(string str)
{
if(str.length()>10)
cout<<"String Length > 10"<<endl;
else if(str.length()<10)
cout<<"String Length < 10"<<endl;
else
cout<<"String Length = 10"<<endl;
}
int main()
{
   string str1 = "Four Score and Seven Years Ago";
   sayStringLength(str1);
string str2 = "Good Day";   
sayStringLength(str2);
string str3 = "0123456789";
sayStringLength(str3);
}


Related Solutions

Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other.
a) Write C code initialize an array of ints to the last four digits of your...
a) Write C code initialize an array of ints to the last four digits of your phone number. Use a loop to add the digits. Calculate and display the average of the digits. b) Write C code using a struct to hold student information: integer id integer number of hours taken integer number of hours passed double gpa
Hw questions 1. Write a single C++ statement that will:      Print the string “C++” using the...
Hw questions 1. Write a single C++ statement that will:      Print the string “C++” using the variable:       string s = “Introduction to C++”. 2. Change the letter ‘c’ to ‘C in the following string:    Reprint the string with “C”  given the code and using the string: string greeting = “Introduction to c++” 3. Write the C++ statement or statements that will:    Print the answer for regular division of the real numbers a / b + c and print the answer for integer...
Write a C program that evaluates the factorials from 1 to 5. Print results in a...
Write a C program that evaluates the factorials from 1 to 5. Print results in a tabular format.
Write a method in c# to find the summation of which two neighboring digits is equal...
Write a method in c# to find the summation of which two neighboring digits is equal to 8 Ex if N =0176623509808 Output is: 17 ,62 ,35 ,80 , 08
Part C (25 pts) Coding question Create a Java class name Store_XXXXX with last 5 digits...
Part C (25 pts) Coding question Create a Java class name Store_XXXXX with last 5 digits of your student ID and write your code in there. A PC store sells many types of computers. The PC can have either 16 or 8 gigabytes of memory. The quality of the PCs can be either New, Refurbished, or Dented. The price list is given as follows: Memory size/Status New Refurbished Dented 16 gigabytes 849.99 729.99 609.99 8 gigabytes 699.99 579.99 439.99 Determine...
Write a C function to swap the first and last elements of an integer array. Call...
Write a C function to swap the first and last elements of an integer array. Call the function from main() with an int array of size 4. Print the results before and after swap (print all elements of the array in one line). The signature of the arrItemSwap() function is: void arrItemSwap(int *, int, int); /* array ptr, indices i, j to be swapped */ Submit the .c file. No marks will be given if your pgm does not compile...
{4, 6, 12, 15, 19, 23, 24}   Write one statement to print out (cout) the first...
{4, 6, 12, 15, 19, 23, 24}   Write one statement to print out (cout) the first character and the last character of the vector you initialized Write one statement to insert an integer 9 to myvec between numbers 6 and 12. in c++
C++ Write a program that asks a teacher to input a student’s first name, last name,...
C++ Write a program that asks a teacher to input a student’s first name, last name, and four test scores. The program should find the average of the four test scores and should then write the following information to a file named “students.txt” last_name first_name average A student's first name of “XX” should be used as a sentinel value and no numeric grades less than 0 or greater than 100 should be accepted.  The program should then read the information in...
When all of the entries are valid, display an account number that shows first 3 digits of the telephone number and first two letters of the last name.
When all of the entries are valid, display an account number that shows first 3 digits of the telephone number and first two letters of the last name. using name John Smith phone number 1234567893 Using net beans take the first two letters from smith and first 3 numbers from the phone number and combine them to one line like this sm123.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT