117639449 CBSE Class XI Computer Science Notes

Embed Size (px)

Citation preview

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    1/31

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    2/31

    Q4:Write a program to check is a number is multiple of three or not.

    Answer:

    #include int main(){int x;cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    3/31

    You can check the size of a variable allocated by a compiler by using sizeofoperator.

    #include #include

    intmain(){

    clrscr(); // clear the screen// using sizeof opeator to find the size of variablecout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    4/31

    getch();

    return0;

    }

    Q3: Consider the following C++ snippet:

    intx = 25000;

    inty = 2*x;

    cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    5/31

    Q5: What are different escape sequences or escape characters in C++?

    Answer: Any character preceded by a backslash, \, is called an escape sequence, or escape character. In

    general, escape characters are used to print special characters. Here is the list of escape characters:

    Escape Sequence Meaning

    \a Terminal Bell

    \b Backspace

    \f Form Feed (Used in printers)

    \t Tab space (equal to four spaces)

    \n New Line

    \r Carriage Return

    \v Vertical Tab

    \\ Backslash

    \' Terminal Bell

    \" Terminal Bell

    \? Terminal Bell

    \000 Octal Number

    \xhh Hexadecimal Number

    \0 Null character

    Following snippet shows the use of escape sequence.

    ?

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    #include

    #include

    voidmain(){

    // following line will print Hello C++ is fun.

    cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    6/31

    Q6: Why the Salesmen didn't get any commission?

    A business man gives 3% commission to his salesman on sales done by that sales man. He asked

    the programmer to write a C++ program to compute commission. To his surprise, none of the

    salesman got any commission. What's wrong with following snippet?

    ?

    12

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    1415

    16

    17

    #include

    #include

    voidmain()

    {

    // define float variables

    floatsales, comm;

    cout > sales;

    // compute the commission

    comm = (3/100)* sales;

    // following uses tab spaces.

    cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    7/31

    Q2: Write a program to display a number in hexadecimal, octal and decimal form.

    Answer: The header iomanip.hdefines hex, oct and dec format flags to display numbers in respectivenumber systems. (e.g. 15 will become 0f in hexadecimal notation and 17 in octal system).By default C++ uses decimal format to display numbers. To display numbers in uppercase (e.g. 0Finstead of 0f), we usesetiosflags(ios::uppercase) manipulator. ios::uppercase shows hexadecimaland scientific numbers in uppercaseSimilarly, to display base format e.g. (hexadecimal uses 0x notation), use manipulatorsetiosflags(ios::showbase).

    ?

    123456789101112131415161718192021

    #include #include #include

    intmain(){clrscr(); // clear the screen

    intx = 27;cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    8/31

    567891011

    121314151617181920

    intmain(){clrscr(); // clear the screenintx = 27;intp = 2, q = -4, r = 0;floatfval = 100.12;

    cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    9/31

    10111213141516

    1718192021

    cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    10/31

    D. CBSE Class 11 - Computer Science - Simple C++ Snippets (Part-4)

    Sequence & Series

    Q1: Write a program to to find the sum of series as: S = 1

    2+ 2

    2+ 3

    2+ ... + n

    2

    Answer:

    ?

    123456

    789101112131415161718192021

    22232425262728

    // program to find sum of series// S = 1^2 + 3^2 + 5^2 + ... + n^2 //#include #include #include

    intmain(){clrscr(); // clear the screenunsigned intn;unsigned longsum;clrscr();cout > n;sum = 0;cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    11/31

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    12/31

    15161718192021

    222324252627282930313233343536

    cin >> x;k = -1;

    for(inti = 1; i

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    13/31

    15161718192021

    222324252627282930313233

    for(inti = 0; i < 10; ++i){// print first two fibonacci numbersif(i == 0)cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    14/31

    22232425262728

    2930313233

    for(i = 0; i < 10; ++i){

    // check if number is even, then addif(arr[i] % 2 == 0){

    sum += arr[i];evens++;

    }}cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    15/31

    E. CBSE Class 11 - Computer Science - Simple C++ Snippets (Part-5)User Defined Functions

    Q1: Write a function to return the largest number among three integers

    Answer:

    ?

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    2223

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    3536

    37

    38

    39

    40

    41

    // function to return the largest number among three integers

    //

    // function declaration

    intlargest_num(int, int, int);

    #include

    #include

    intmain()

    {

    clrscr(); // clear the screen

    intx, y, z;

    cout > x;

    cout > y;

    cout > z;

    cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    16/31

    Q2:What is function definition?

    Answer: A function definition describes how the function computes the value it returns. It is a declaration

    about the function. It is also called function prototype. In general it is defined before using the function,

    within in the source file or in header (.h/.hpp) files.

    Q3(Text Book): Write a C++ program that reads a float array having 15 elements. The program uses a

    function reverse( ) to reverse this array. Make suitable assumptions wherever required.

    Answer:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    2223

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    3536

    37

    38

    39

    40

    41

    42

    // // program to reverse an array

    //

    #include

    #include

    // functions declaration

    voidreverse(floatarry[], intsize);

    voiddisplay(floatarry[], intsize);

    intmain()

    {

    clrscr(); // clear the screen

    floatflist[15] = {12.2, 8.1, 6.75, 18.25, 30.18, 12.5, 56.0,

    78.12, 10.24, 13.12, 34.65, 16.80, 12.23,

    32.5, 11.25};

    display(flist, 15);

    cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    17/31

    Q4(Text Book): Write a complete C++ program that invokes a function satis( ) to find whether four

    integer a,b,c,d sent to satis( ) satisfy the equation a3+ b

    3+ c

    3= d

    3or not. The function satis( )

    returns 0 if the above equation is satisfied with the given four numbers otherwise it returns -1.

    Answer:

    ?

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    1213

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    2526

    27

    28

    29

    30

    31

    32

    33

    34

    35

    36

    // function satis()

    /* wap to find whether 4 integers a,b,c,d sent to satis() satisfy the

    eq. a^3 + b^3 + c^3 = d^3*/

    //

    #include

    #include

    #include

    // functions declaration

    intsatis(int, int, int, int);

    voidmain()

    {

    clrscr();

    cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    18/31

    Answer:

    ?

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    2930

    31

    32

    33

    34

    35

    36

    37

    38

    39

    40

    41

    4243

    44

    45

    46

    47

    48

    49

    50

    // functions

    /* wap that uses the function sqlarge() that is passed two int arguments by

    reference & then sets the larger of the two nos.to its square*/

    //

    #include

    #include

    // functions declaration

    voidsqlarge(int&, int&);

    intsum(intnum);

    voidmain()

    {

    intfirst, second, sqnum;

    clrscr();

    cout > first;

    cout > second;

    sqlarge(first, second);

    if(first > second)

    sqnum = first;

    else

    sqnum = second;

    cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    19/31

    }

    returns;

    }

    Q6: Write a c++ function swap( ) to swap to integers passed to the function.

    Answer:

    ?

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    1112

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    2425

    26

    27

    28

    29

    30

    31

    32

    33

    34

    // // function swap() to swap two numbers

    //

    #include

    #include

    // functions declaration

    voidswap(int& x, int& y);

    voidmain()

    {

    clrscr();

    clrscr();

    inta,b;

    cout > a;

    cout b;

    cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    20/31

    F. CBSE Class 11 - C++ Snippets (Part-6)

    Graphics Support in TCTurbo C++ has support for various DOS mode graphics (CGA, VGA, SVGA etc.).

    Various graphics functions are supported in GRAPHICS.LIB. You need to include file inyour code.Following are essential functions to be called to invoke graphics mode:

    initgraph( ): initializes the application to work in graphics mode. It takes three arguments, DETECT,graphics mode and path of *.BGI files.

    closegraph( ): closes the graphics mode and switches the application back to test mode.

    It supports various graphics functions (e.g. circle, setlinestyle, drawpoly, arc, ellipse...) to draw variousgraphics primitives. You can fill the graphics object with different colour values and can control the colorpalette.

    Q1:Write a sample program to show graphics mode working of TC++

    Answer:

    ?12345678910

    /* Simple example to draw circle */#include #include #include #include

    voidmain(){

    http://1.bp.blogspot.com/-BZtbWRaz20s/UM6QvEImzkI/AAAAAAAAEyg/yDqLgpaj_Y8/s1600/cl11_cplus_snip6_Fig1.jpg
  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    21/31

    11121314151617

    181920212223242526272829303132

    333435363738394041

    intgd=DETECT,gm;initgraph(&gd, &gm, "c:/tc/bgi "); // initialize graphics mode./* read result of initialization */interrorcode = graphresult();if(errorcode != grOk) /* an error occurred */{cout

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    22/31

    (d) Multi-core processors

    Q3:Full form of ALU is ___.

    (a) Application Logic Unit(b) Array Logic Unit(c) Arithmetic Logic Unit(d) Auxiliary Logic Unit

    Q4: Antivirus is a type of which software?

    (a) Application Software(b) Utility Software(c) System Software(d) Firmware

    Q5: Spreadsheet is an example of _____.

    (a) Application Software

    (b) Utility Software(c) System Software(d) Firmware

    Q6: ____________ is data that has been organized or presented in a meaningful manner.

    (a) Process(b) Database(c) Software(d) Information

    Q7: Compiler is an example _____.

    (a) Application Software(b) Utility Software(c) System Software(d) Firmware

    Q8: Which of the following is not a DBMS?

    (a) Oracle(b) MS-Access(c) Excel

    (d) Foxpro

    Q9: An error in a software is often referred as ___.

    (a) squid(b) leech(c) bug(d) virus

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    23/31

    Q10: Personal computers use a number of chips mounted on a main circuit board. This mainboard is often referred as:

    (a) Motherboard(b) Breadboard(c) Masterboard(d) Fatherboard

    Q11: Which one of the following is NOT a computer language?

    (a) Oracle(b) C++(c) FORTRAN(d) PASCAL

    Q12: A computer program that converts an entire program into machine language is calleda/an

    (a) Interpreter(b) Compiler

    (c) Linker(d) Simulator

    Q13: Which of the following is a main memory?

    (a) Hard Disk(b) RAM(c) Optical Disk(d) Floppy Disk

    Q14: Which of the following is not a multi-user operating system?

    (a) DOS

    (b) Windows 2003 Server(c) Linux(d) UNIX

    Q15: CAD stands for ______

    (a) Computer Aided Design(b) Complex Algorithm Design(c) Computer Application Design(d) Computer Accessory Design

    Q16: 4 bits constitute to form ___(a) A byte

    (b) A nibble(c) A kilobit(d) Two Bytes

    Q17: A computer is free from tiredness, monotony etc. reflects which characteristic?(a) High Speed(b) Accurate(c) Versatile(d) Diligence

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    24/31

    Q18: Who is known as 'Father of Modern Computers'? (a) Blaise Pascal(b) Charles Babbage(c) Von Leibniz(d) John Neuman

    Q19: UNIVAC was the first commercial computer designed in USA in 1951. What is the fullform of UNIVAC?(a) Universal Array Computer(b) Universal Automatic Computer(c) United Array Computer(d) United Automatic Computer

    Q20: Who is the developer of C++ language? (a) Van-Neumann(b) Dennis M. Ritchie(c) Donald Kunth(d) Bjarne Stroustrup

    Q21: Who was the developer of C language?

    (a) Van-Neumann(b) Dennis M. Ritchie(c) Donald Kunth(d) Bjarne Stroustrup

    Q22: Who invented 'Analytical and Difference Engine'?(a) Van-Neumann(b) Charles Babbage(c) Donald Kunth(d) Von Leibniz

    Q23: Who is known as 'Father of Analysis of Algorithms'?

    (a) Van-Neumann(b) Dennis M. Ritchie(c) Donald Kunth(d) Bjarne Stroustrup

    Q24: MS Excel is a/an ____.(a) word processor software(b) image processing software(c) spreadsheet package(d) multimedia player

    Q25: Which one of the following is an impact printer?(a) Inkjet printer(b) Daisy wheel printer(c) Laser printer(d) Thermal image printer

    (more to come...)

    Answers:

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    25/31

    1. (b) American Standard Code for Information Interchange2. (a) Vacuum Tubes3. (c) Arithmetic Logic Unit4. (b) Utility Software5. (a) Application Software6. (d) Information7. (c) System Software8. (c) Excel9. (c) bug10. (a) Motherboard11. (a) Oracle12. (b) Compiler13. (b) RAM14. (a) DOS15. (a) Computer Aided Design16 (b) a nibble17 (d) Diligence18 (b) Charles Babbage19 (b) Universal Automatic Computer20 (d) Bjarne Stroustrup

    21 (b) Dennis M. Ritchie22 (b) Charles Babbage23 (c) Donald Kunth24 (c) spreadsheet package25 (b) Daisy wheel printer

    CBSE Class 11/10 - Computers/FIT - Programming

    Languages

    Programming Languages

    (Questions & Answers)

    Q1: What is a computer language?

    Answer: The instructions are fed into computers in the form of computer programs, follow somesemantics (grammar or syntax) collectively is called a programming language. In layman terms, the

    http://1.bp.blogspot.com/-f1Cha0GSB44/UJcb8i1IX8I/AAAAAAAADwY/a-EQhdGhcE8/s1600/proglanguages.jpg
  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    26/31

    language, which the user employs to interact with computer, is known as computer or programminglanguage.

    Examples are: C/C++, Java, Pascal, COBOL, Python, FORTRAN etc.

    Q2: What are different generation of languages?

    Answer: A good number of languages have been developed so far, therefore all computer languages aredivided among different generations of languages:

    1. The first generation languages (1GL) are low-level languages that are machine language.2. The second-generation languages (2GL), ar also low-level languages that consist of assembly

    language.3. The third generation languages(3GL) are high-level languages such as C.4. The fourth generation languages (4GL) are languages that consist of statements similar to

    statements used in a human language.5. The fifth generation languages(5GL) are programming language based around solving problems

    following constraints-driven approach rather using an algorithm-driven approach.A good exampleof a fifth generation language is PROLOG.

    Q4: What were different types of problem-solving approaches which led to the basis of computer-based solving and design of computer languages?

    Answer: Various problem solving approaches which were initially used in computer based solving anddesign of computer languages are:

    1. Look for similar patterns or situations (Table look up)2. Divide and Conquer3. Heuristics (rule of thumb)4. Algorithms

    Machine Code

    (Hex View of .exe file)

    Q5: What is a machine language?

    Answer: Machine Language was the first generation programming language which is hard wired inprocessors. It is also referred as machine code or object code. Machine language instructions are builtinto the hardware of a particular computer. It is a collection of binary digits or bits that the computer readsand interprets. Machine language is the finite number of instructions that only a computer canunderstand.

    http://2.bp.blogspot.com/-nL-2J08AmdE/UJcciDaiIPI/AAAAAAAADwg/VMKh2-7xAB4/s1600/machine_code.jpg
  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    27/31

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    28/31

    debuggingcredits:openclipart

    Answer: A computer bug is a any type of problem, defect or mistake in a program/software or in ahardware.

    Q10: What is debugging?

    Answer: The process of identifying and removing a defect in hardware or software is called debugging.

    Q11: What are the advantages of assembly language over machine language?

    Answer: As compared to machine language, assembly language has the following advantages:

    1. Easier to write code.2. Easier to debug program.3. Easy to modify program, reduce maintenance cost.4. Useful for writing small, real time applications for embedded devices.

    Q12: What is an assembler?

    Answer: Assembler is a system program which translates an assembly language code or program tomachine code format. Generally assemblers are written by the manufacturers of processors becauseassemblers are machine dependent.

    Q13: What are the limitations of coding in assembly language?

    Answer: Following are the limitations of coding in assembly language:

    1. Machine Dependent: Since mnemonics are processor specific, one needs to port or translatehis/her program while switching to another machine (processor model).

    2. Hardware knowledge is prerequisite. It because necessary to know about CPU and its hardware.3. Increase maintenance cost. Due to above said two factors, it increases the maintenance cost for

    managing software.

    Q14: What are high-level languages?

    Answer: High level languages or 3rd generation languages use English like statements to code computerinstructions. These are programmers' friendly since these languages are machine-independent anddevelopers can concentrate on problem solving logic rather than on hardware structure. These languagesrequire system programs called compilers (and interpreters) which translate English-like statements(source code) to machine code.

    Examples of high level languages are: C, C++, Java, COBOL, BASIC, FORTRAN, Pascal etc.

    Q15: Write full form of following computer language abbreviations

    http://openclipart.org/detail/63559/debugging-by-mazeohttp://openclipart.org/detail/63559/debugging-by-mazeohttp://openclipart.org/detail/63559/debugging-by-mazeohttp://2.bp.blogspot.com/-DZgRnFQYx70/UJcmHuOyVsI/AAAAAAAADyw/oxDBWYkJoe4/s1600/assembler.jpghttp://openclipart.org/detail/63559/debugging-by-mazeohttp://openclipart.org/detail/63559/debugging-by-mazeo
  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    29/31

  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    30/31

    Q18: What are the main advantages of High Level Languages?

    Answer: High Level language have the following advantages over using assembly and machinelanguage:

    1. Machine Independent: A high level language written code can easily be ported to anotherhardware platform. Language instructions do not reply on characteristics of a machine hardware.2. Easy to Learn: Since the HLL instructions are English like statements, these are easier to learn.3. Closer to Design Process: The design process is better suited for HLLs as compared to low level

    languages. Implementing various programming techniques, algorithms and data structures ismuch easier in HLLs.

    4. Few Errors and Easy Debugging: Since the programmer need not worry about hardwareinstructions, he can concentrate more on developing program logic.

    5. Low development Cost: Writing programs in high level languages take less time as compared tocoding in low level languages.

    6. Low maintenance cost: Programs are easier to manage. One can find errors easily and rectifythem thus reducing the maintenance cost.

    7. Better Documentation: Since HLLs are English language statements and hence easier tounderstand. The code is self-explanatory and requires less commenting.

    Q19: What are the limitations of High level languages?

    Answer: Although HLLs have numerous advantages over low level languages but it does have certainlimitations:

    1. Large time to execute: A HLL translated machine code is bigger in size than low levelprogrammed code. Thus HLL translated code takes larger time to execute.

    2. Less optimized code: Sometimes it is required to write a small sized efficient programs becauseof memory and performance constraints (e.g. embedded devices which use CPUs do not havelarge memory and need faster response). In this case, coding in assembly is better alternative.

    3. Managing Growing complexity is a challenge: As the code size of a software grows, the

    complexity to manage its code also increases. One needs to apply various disciplinary actions ofsoftware engineering and code management to produce a reliable software. This indeedincreases the managing cost.

    Q20: Who designed 'C' language?

    Answer:Dennis Ritchie

    Q21: Who designed 'C++' language?

    Answer:Bjarne Stroustrup

    Q22: Who designed BASIC language?

    Answer: John George Kemeny and Thomas Eugene Kurtz at Dartmouth College

    Q23: Who developed Visual Basic?

    Answer: Microsoft Team

    Q24: Who is known as Father of Computers?

    http://en.wikipedia.org/wiki/Dennis_Ritchiehttp://en.wikipedia.org/wiki/Dennis_Ritchiehttp://en.wikipedia.org/wiki/Dennis_Ritchiehttp://en.wikipedia.org/wiki/Bjarne_Stroustruphttp://en.wikipedia.org/wiki/Bjarne_Stroustruphttp://en.wikipedia.org/wiki/Bjarne_Stroustruphttp://en.wikipedia.org/wiki/Bjarne_Stroustruphttp://en.wikipedia.org/wiki/Dennis_Ritchie
  • 8/10/2019 117639449 CBSE Class XI Computer Science Notes

    31/31

    Answer: Charles Babbage

    Q25: Name the language which was named after a lady who was the daughter of poet LordByron. She worked with Charles Babbage to develop plans for the Analytical Engine.

    Answer: Ada (and the lady wasAugusta Ada Byron, countess of Lovelace.Also referred as the firstknown programmer.) Ada is a object oriented high level language.

    Q26: What are fourth generation languages (4GL)? How are 4GLs different from thirdgeneration languages?

    Answer: Fourth generation languages (4GLs) are English like statements commonly used to accessdatabases. These are called command languages or non-procedure languages because theselanguages help the user obtain desired results without writing long program or procedures (as it isdone in 3rd generation languages). 4GLs are more oriented towards non-technical users and reducecoding errors. Examples of 4GLs are SQL, DBMS, spreadsheets, FOCUS, report generator etc.

    http://en.wikipedia.org/wiki/Ada_Lovelacehttp://en.wikipedia.org/wiki/Ada_Lovelacehttp://en.wikipedia.org/wiki/Ada_Lovelacehttp://en.wikipedia.org/wiki/Ada_Lovelace