1. Given the following string variables, write a statement that would add str2 t
ID: 3639112 • Letter: 1
Question
1. Given the following string variables, write a statement that would add str2 to the end of str1. Do not use an assignment statement to do this.string str1 = "Here is an ";
string str2 = "example string";
2. Given the following string variable, write a statement that would output the number of characters in str1.
string str1 = "Here is an example string";
3. Create an output format statement that would generate lines in the table which appear as shown below. The Item Description Field displays a description of the item contained in the desc variable. YYYY displays an integer value from the qty variable which ranges from 1 thru 9999 and should be right justified. XXXX.XX displays a monetary value from the cost variable which ranges from 0.01 to 9999.99 and should also be right justified. Use the variables shown below in your output statements.
Item Description Field........YYYY.....$XXXX.XX
string desc; int qty; double cost;
4. Write a function called AnalyzeData. This function is passed a double array along with a parameter that indicates the number of elements in the array. It is also passed a double value. The function computes and returns the number of values in the array that are greater than this double value. Write a complete C++ function to do this operation. There is no cin or cout in this function. This is only a function, so there is no main routine here!
Explanation / Answer
please rate - thanks
message me if any questions -- I tested all of them
1. Given the following string variables, write a statement that would add str2 to the end of str1. Do not use an assignment statement to do this.
string str1 = "Here is an ";
string str2 = "example string";
str1=str1.append(str2);
2. Given the following string variable, write a statement that would output the number of characters in str1.
string str1 = "Here is an example string";
cout<<"The length of "<<str1<<" is: "<<str1.length();
3. Create an output format statement that would generate lines in the table which appear as shown below. The Item Description Field displays a description of the item contained in the desc variable. YYYY displays an integer value from the qty variable which ranges from 1 thru 9999 and should be right justified. XXXX.XX displays a monetary value from the cost variable which ranges from 0.01 to 9999.99 and should also be right justified. Use the variables shown below in your output statements.
Item Description Field........YYYY.....$XXXX.XX
string desc; int qty; double cost;
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{string desc="description"; int qty=3; double cost=5.2;
cout<<setw(30)<<left<<desc<<setw(4)<<right<<qty<<" $"<<setw(7)<<setprecision(2)<<fixed<<right<<cost<<endl;
system("pause");
return 0;
}
you want the line that's in blue
I wasn't sure how wide description is , I made it 30
4. Write a function called AnalyzeData. This function is passed a double array along with a parameter that indicates the number of elements in the array. It is also passed a double value. The function computes and returns the number of values in the array that are greater than this double value. Write a complete C++ function to do this operation. There is no cin or cout in this function. This is only a function, so there is no main routine here!
int AnalyzeData(double a[],int n,double m)
{int i,count=0;
for(i=0;i<n;i++)
if(a[i]>m)
count++;
return count;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.