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

Can someone convert this code to use printf & scanf instead of cin and cout #include...
Can someone convert this code to use printf & scanf instead of cin and cout #include <iostream> int main() { int n, i = 0; float RF, PFD, Tn = 0, Ts; std::cout << "**** Welcome to the Time Study Program ****" << std::endl; std::cout << "\nEnter the number of elements for the given operation being performed" << std::endl; std::cout << "Number of Elements: "; std::cin >> n; if (n < 0) { std::cout << "\nNumber of elements cannot be...
***Convert the C++ to Python*** #include <iostream> using std::cout; using std::cin; using std::endl; int charClass; char...
***Convert the C++ to Python*** #include <iostream> using std::cout; using std::cin; using std::endl; int charClass; char lexeme[100]; char str[200]; char nextChar; const int LETTER = 0; const int DIGIT   = 1; const int UNKNOWN = -1; const int OPAREN = 2; const int CPAREN = 3; const int PLUS = 4; const int MINUS = 5; const int MUL = 6; const int DIV = 7; const int ID_CODE = 100; const int PLUS_CODE = 101; const int MINUS_CODE =...
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?
Write the RE for identifiers that can consist of any sequence of letters (l) or digit...
Write the RE for identifiers that can consist of any sequence of letters (l) or digit (d) or "_" but the first char must be a letter and the last char cannot be a "_" (10)
Write the RE for identifiers that can consist of any sequence of letters (l) or digit...
Write the RE for identifiers that can consist of any sequence of letters (l) or digit (d) or "_" but the first char must be a letter and the last char cannot be a "_"
Write a C++ program that inputs (cin) a word from the keyboard and generates several different...
Write a C++ program that inputs (cin) a word from the keyboard and generates several different scrambles of the word without using vectors. The input word can be from 4 to 10 letters in length. The number of scrambles produced depends on the number of letters in the word. e.g. the 4 letter word “lose” would have 4 different scrambles produced and the seven letter word “edition” would have seven different scrambles. Here is a candidate example:      Input: FLOOR...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT