Deck 9: Strings
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/37
العب
ملء الشاشة (f)
Deck 9: Strings
1
If you want to examine an input value without actually removing it from the input stream,you can apply a member function of cin to the variable ch,which you are to assume is a char type variable.Which of these does this task?
A)cin.get(ch);
B)cin.put(ch);
C)cin.peek(ch);
D)cin.putback(ch);
A)cin.get(ch);
B)cin.put(ch);
C)cin.peek(ch);
D)cin.putback(ch);
C
2
It is legal to assign C-string variables.
False
3
The C-string library functions are safe and require no special care.
False
4
The preprocessor symbol NULL and the C-string terminator,the null character share the value 0
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
5
The C-string library functions use the null terminator to decide when to stop processing.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
6
It is possible to use a standard string with a string member function as source for the strcpy or strcat functions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
7
To read a character at a time,or to write a character at a time,declare a character variable ch and write this:
cin >> ch;
cin >> ch;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
8
The C-string library function strcmp compares two strings for equal length.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
9
The = sign used to give a variable an initial value in a definition,
char ch = 'A';
is different from the = sign in an assignment.
ch = 'B';
char ch = 'A';
is different from the = sign in an assignment.
ch = 'B';
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
10
Indexing for Standard string objects does not range check/
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
11
If you have already removed a character (in char variable ch)from the input stream,you can apply a member function of cin to the variable ch to return it to the input stream.Which of these does this task?
A)cin.get(ch);
B)cin.put(ch);
C)cin.peek(ch);
D)cin.putback(ch);
A)cin.get(ch);
B)cin.put(ch);
C)cin.peek(ch);
D)cin.putback(ch);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
12
A C-string variable is just an array of characters.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
13
A C-string is a sequence of characters terminated by the null character.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
14
ANSI/ISO C++ standard includes a string-handling library in the form of the class string.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
15
C-string literals are written 'Hello'.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
16
A C-string variable is an array,so it can be indexed to access individual character positions (indexed variables of type character).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
17
A C-string variable with a something in it is always filled with characters.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
18
You can assign a standard string to a C-string variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
19
To get a complete line of 70 or so character into a C-string is as simple as declaring a long enough C-string and then using the >> operator to extract the line from the input.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
20
It is illegal to write char message[] ="Go Home!";
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
21
What is the problem (if any)with this code?
char s1[20] = "How you been? ";
strcat(s1,"Fine as wine");
char s1[20] = "How you been? ";
strcat(s1,"Fine as wine");
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
22
The header file that you must #include to have access to the Standard Library string class is
A)C-string
B)string.h
C)string
D)String.h
E)None of the above
A)C-string
B)string.h
C)string
D)String.h
E)None of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
23
Write code to define a C-string aString variable,of size 10 but do not initialize it.Use a library C-string library function to copy the C-string literal,"Hello" into aString.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
24
Given the following definition and initialization.Write a code fragment including a loop that will overwrite the string greeting,with 'X' in all character position,keeping the length the same.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
25
Give the output the following code fragment would produce if embedded in a correct and complete program?
char singing[20] = "Hi De Hi";
strcat(singing,",Hi De Ho!");
char singing[20] = "Hi De Hi";
strcat(singing,",Hi De Ho!");
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
26
What is a simple way to convert a string to a numeric value in C++11? This is sometimes needed when data is input as a string but we need to perform numeric computations on the values.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
27
Write a C++ program fragment that will read a line of text and echo the line with all uppercase letters deleted.Declare variables and include necessary header.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
28
Write a complete program with necessary #include directives to copy the C-string constant "Hello" into the string variable aString,declared below.
char aString[10];
char aString[10];
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
29
On most systems,you don't get a chance to enter the letter when the code given below is run.Write two different code fragments that repair the problem.
cout << "Enter a number:\n";
int number;
cin >> number;
cout << "Enter a letter;\n";
char symbol;
cin.get(symbol);
cout << number << " " << symbol << endl;
Dialog: (Computer output is bolded. )
Enter a number:
21
Now enter a letter:
21
On my system,like many systems,one doesn't get a chance to type the letter.
cout << "Enter a number:\n";
int number;
cin >> number;
cout << "Enter a letter;\n";
char symbol;
cin.get(symbol);
cout << number << " " << symbol << endl;
Dialog: (Computer output is bolded. )
Enter a number:
21
Now enter a letter:
21
On my system,like many systems,one doesn't get a chance to type the letter.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
30
What is the longest C-string that can be put into this C-string variable? Explain.
char s[9];
char s[9];
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
31
Write a line of code that declares and initializes a C-string variable,yourString,that can hold up to 10 characters.Use the initialization string "Whoops".
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
32
Does this code have a problem?
char strVar[] = "Hello";
strcat(strVar," And Good-bye.");
cout << strVar << endl;
char strVar[] = "Hello";
strcat(strVar," And Good-bye.");
cout << strVar << endl;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
33
Write a short C++ code fragment that reads a line of text and echo the line with all uppercase letters replaced by asterisks.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
34
Reimplement the function strlen.Call your function strLen.The library function,strlen takes one char str[] argument,so you give strLen a char str[] argument as well.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
35
Write an if-else statement using a C-string function that reports whether two C-strings variables contain the same C-string.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
36
You are writing bulletproof input.Describe a simple situation in this setting where you need to know what character has been entered by the user of your program before you remove it from the input stream.Just describe the setting,do not attempt to write code for this.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck
37
What is the problem with this bit of code? On most systems,you don't get a chance to enter the letter.Why?
cout << "Enter a number:\n";
int number;
cin > number;
cout << "Enter a letter;\n";
char symbol;
cin.get(symbol);
cout << number << " " << symbol << endl;
Dialog: (Computer output is bolded. )
Enter a number:
21
Now enter a letter:
21
cout << "Enter a number:\n";
int number;
cin > number;
cout << "Enter a letter;\n";
char symbol;
cin.get(symbol);
cout << number << " " << symbol << endl;
Dialog: (Computer output is bolded. )
Enter a number:
21
Now enter a letter:
21
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 37 في هذه المجموعة.
فتح الحزمة
k this deck