+1 and +2 Computer Science

Previous Question paper answered , and Questions from Textbook

+1 and +2 Computer Application

Previous Question paper answered , and Questions from Textbook

Diploma in Computer Application (DCA)

Previous Question paper answered , and Questions from Textbook.

Master of Computer Applications (MCA)

Previous Question paper answered , and Questions from Textbook

True IQ Computer Online Academy

Contact : +91 9036433020 , mail2trueiq@gmail.com

Pageviews

Showing posts with label String Handling and I/O Functions. Show all posts
Showing posts with label String Handling and I/O Functions. Show all posts

Tuesday, 28 July 2020

+1] 9 -String handling And Input Output functions - Solved Questions chapter wise



                                  PLUS ONE COMPUTER SCIENCE

                First year computer science Solved Questions and answers

                                                              Chapter  -  
                                         String Handling and I/O Functions





1. Which character is used to delimit the string in memory?

  Ans. Null character(/0)

 2. Write the statement to declare a variable for storing "Save Earth".

 Ans. char name[11];

3. Name the header file required for using console I/O functions.

 Ans.csdtio

4. How many bytes are required to store the string "Be Positive"?

    Ans. 12 bytes.

5. How does puts("hello"); differ from cout<<"hello";?

   Ans.  C++ gives a console function named puts() to output string data. The function puts() is a console output function used to display a string data on the standard output device (monitor). Its syntax is: puts(string_data);
puts("hello");
puts(str); the ouput will be hello.
Using cout<<“hello”; and cout<<str; instead of the
puts() functions and see the difference. The output will be in the same line without
a space in between them in the case of cout statement.

6. Name the stream function to input a character data.

  Ans. get( )

7. Write a C++ statement to display the string "Smoking is injurious to health" using write() function.

    char str[31]="Smoking is injurious to health";

    cout.write(str,31);

8. Name the header file required for using stream I/O functions.

    Ans.  iostream

9. Write down the syntax of getline() function.

  Ans. getline(str,len);

10. What will the output of the statement: putchar(97); be?

  Ans. a (small letter )

 11. Distinguish between console functions and stream functions.

    Ans.  C++ also provides some functions for performing input/ouput operations on characters. These functions require the inclusion of header file cstdio in the program.getchar(),putchar() are the console functions in I/O functions.
C++ provides another facility to perform input/output operations on character and strings. It is in the form of functions that are available in the header file iostream. These functions are generally called stream functions since they allow a stream of bytes (data) to flow between memory and objects.

 12. Write a C++ statement to input the string “Computer” using get() function.

     Ans. char ch, str[9]; 

              ch=cin.get(ch);

 13. Write down the output of the following code segment:

      puts(“hello”);

       puts(“friends”);

Ans. hello

         friends 

14. Predict the output of the following code segment:

       char str[] = “Program”;

       for (int i=0; str[i] != ‘\0’; ++i)

     {

       putchar(str[i]);

      putchar(‘–’);

}

   Ans. P-r-o-g-r-a-m

15. Identify the errors in the following program and give reason for each.

#include<iostream>
using namespace std;
int main()
{
char ch, str[10];
write(“Enter a character”);
ch=getchar();
puts(“Enter a string”);
cin.getline(str);
cout<< “The data entered are “ <<ch;
putchar(str);
}

16. Observe the following functions. If the statement is valid, explain what happens
when they are executed. If invalid, state reasons for it. (Assume that the variables
are valid)

(a) getchar(ch);

 (b) gets(str[5]);

(c) putchar(“hello”);

(d) cin.getline(name, 20, ‘,’);

 (e) cout.write(“hello world”, 10);

    Ans.

                a. Invalid.Correct statement ch=getchar(ch);

                 b. Invalid. Correct statement gets(str);

                  c. Invalid. Putchar is displaying only single character

                   d. Valid

                   e. valid

17. Read the following statements:

char name[20];
cin>>name;
cout<<name;

What will be the output if you input the string “Sachin Tendulkar”? Justify
your answer. Modify the code to get the entered string as the output.

  Ans. The output will be displayed Sachin.cin statement read till a white space

  char name[20];
  gets(name);
  puts(name);

                     Essay questions  refer  text book chapter 9

18 Explain the console I/O functions with examples.

19. Briefly describe the stream I/O functions with examples.




















Thursday, 14 November 2019

+1] 9 - String Handling and I/O Functions - Previous Questions Chapter wise



                          PLUS ONE COMPUTER SCIENCE

            First Year Computer Science Previous Questions Chapter wise ..

                           Chapter-9 String Handling and I/O Functions



1. Consider the following C++ program.

#include<iostream>

using namespace std;

int main()

{

char str[20];

cin>>str;

cout<<str;

}
What will be the output if we input the string “Vande Mataram”. Justify your answer.

2. What is the advantage of using gets() function in C++ program to input string data?
Explain with an example.

          The gets() function enables the user to enter some characters followed by the enter key. All the characters entered by the user get stored in a character array. The null character is added to the array to make it a string. The gets() allows the user to enter the space-separated strings.

3. a) Write the declaration statement for a variable ‘name’ in C++ to store a string of maximum length 30.
 b) Differentiate the statements cin>>name; and gets(name); for reading data to the variable ‘name’.

       
Ans. a)  char name[30];  

b). Usually the input device is the keyboard. cin is the instance of the class istream and is used to read input from the standard input device which is usually keyboard.The extraction operator(>>) is used along with the object cin for reading inputs. The extraction operator extracts the data from the object cin which is entered using the keboard.

        A string can be input using the statement cin>>name; This statement can store a string without any white space (that is, only one word). If we want store strings containing white spaces (strings having more than one word) we can use gets() function.That is gets(name);


4.  Consider the following C++ statements:

 char word[20];

cin>>word;

 cout<<word;

 gets(word);

puts(word);

 If the string entered is “HAPPY NEW YEAR”, predict the output and justify your answer.

Ans. "HAPPY NEW YEAR"     17 characters including white spaces between the word,/0 is represent end of the string and 3 white spaces after the word .That is total 20 characters of the word.

5. a) my_name is a variable contains a string. Write two different C++ statements to display the string.     

b) …… function is used to copy a string to another variable.

Ans.

        b) strcpy( )

6. Read the following code:

char str[30];

 cin >> str;

cout << str;

If we give the input “Green Computing”, we get the output “Green”. Why is it so? How can you correct that?

   To change the