Question

In: Computer Science

1) As mentioned in this chapter, C++ predefined identifiers such as cout and cin can be...

1) As mentioned in this chapter, C++ predefined identifiers such as cout and cin can be redefined by the programmer. However, why is it not wise to do so?

2) The text mentioned that the char data type can be cast into an int. What are some possible uses of this functionality?

3) Introduce the C++ data type string, which is a programmer-defined data type available in the C++ library. Define a string as a sequence of zero or more characters.

Please explain in detail.

Solutions

Expert Solution

1)

Ans:- Of course the classes ostream and istream are user defined but as a user of c++ we can't modify the those classes and they are not built in c++ so modify those function definition is not good idea.

2)

Ans:- To get the equivalent integer we can use ASCII value of that char or you will get the equivalent char of ASCII integer value

for example

#include <iostream>

using namespace std;

int main()   
{
char ch = 'A';
int n = (int)ch;
cout<< n<<endl;
cout<<(char)65;
return 0;
}

3)

Ans : -You'll need to include the library of string class #include <string> as the header file, it is type of char * or char[] type

#include<iostream>
#include<string> // for string class
using namespace std;
int main()
{
// Declaring string
string str = "000000000000111AAA";
  
   cout<<str;
   return 0;
  
}

Please let me know if you have any doubt or modify the answer, Thanks :)


Related Solutions

C++: How are std::cout << “hello world” and std::cout << “hello” << ‘ ‘ << “world”...
C++: How are std::cout << “hello world” and std::cout << “hello” << ‘ ‘ << “world” different?
write this program in c++ using iostream library.( cin>>n; cin>> arr[n] and so on) Write a...
write this program in c++ using iostream library.( cin>>n; cin>> arr[n] and so on) Write a function that converts an array so that in the first half settled with elements from odd positions, and in the second half - with elements from the even positions.Positions are counted from the first index.The program have to use pointer. example: input: 7 1 2 3 4 5 6 7 output: 1 3 5 7 2 4 6 8
Describe the rules governing identifiers. Can identifiers be re-used in the same Java class file? Provide...
Describe the rules governing identifiers. Can identifiers be re-used in the same Java class file? Provide three examples of different kinds of invalid identifiers. Java
1. Which of the three parenting approaches mentioned in the chapter do you prefer and why?...
1. Which of the three parenting approaches mentioned in the chapter do you prefer and why? How were you raised? How do you think the way you were raised affects you now? 2. Can you give an example of a cultural script? Do you have any cultural scripts? What are they? 3. How much does self-esteem show? Is it easy to tell who has high-esteem and who doesn't? The text says that people aren't always what they seem. Do you...
The retailer Zara is mentioned in chapter 18 of the Schroeder textbook as an example of...
The retailer Zara is mentioned in chapter 18 of the Schroeder textbook as an example of global logistics. What is unique about Zara's logistics strategy and in what ways has it made them successful?
 VISUAL STUDIO (File Creation and Submissions)  FLOWCHART  Writing program in C++ ( cout,...
 VISUAL STUDIO (File Creation and Submissions)  FLOWCHART  Writing program in C++ ( cout, \n, \t, solving expressions )  Correcting errors Q1: Draw flow Chart of the following problems: a) Display “Hello World” on screen. b) Display Your Name, date of birth and mobile number on screen. c) Compute and display the perimeter and area of a rectangle with a height of 7 inches and width of 5 inches. d) Compute and display the perimeter and area...
. Throughout this chapter, investor expectations are mentioned. Could this account for much of the volatility...
. Throughout this chapter, investor expectations are mentioned. Could this account for much of the volatility in the stock market? Investors adjust their expectations as they receive information, and thanks to technology like hand-held computers and cell phones, receipt of information is nearly instantaneous. Discuss how just the technological changes in the last 10 years have affected the stock market and investors.
distinguish among the two concepts of democracy mentioned in the chapter, explaining in which of these...
distinguish among the two concepts of democracy mentioned in the chapter, explaining in which of these senses the textbook refers to American government. Refer to basic theories of power, liberty and security. Be sure to cite references as required.
Translate c++ code into mips assembly: int main() {                 cout << "Numbers:" << endl;            &nbs
Translate c++ code into mips assembly: int main() {                 cout << "Numbers:" << endl;                                 int x[] = {18, 12, 6, 500, 54, 3, 2, 122};                 int i;                                 for (i=0; i<8; i++)                 {                                                 cout << x[i] << endl;                 }                 return 0; } below is my code: .data        str1: .ascii "Numbers:"     str2: .ascii "\n"    x: .word 18,12,6,500,54,3,2,122       .text                      ...
At the end of Chapter 11, it mentioned "creative destruction." What is the main idea behind...
At the end of Chapter 11, it mentioned "creative destruction." What is the main idea behind that term? 1-The idea that a competitive marketplace will also be a creative one and that we should see new technologies and inventions as entreprenueurs try to "out do" each other. When downloading music became popular this pretty much eliminated the need for physical audio CDs. This was an example of creative destruction. 2-It is highly doubtful that a centrally planned communist economy (i.e....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT