Preview

C++ solution

Good Essays
Open Document
Open Document
459 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
C++ solution
(i) Conversion from Class to Basic Type: We know that conversion from a basic to class type can be easily done with the help of constructors. The conversion from class to basic type is indeed not that easy as it cannot be done using constructors. for this conversion we need to define an overloaded casting operator. This is usually referred to as a conversion function. The syntax for this is as follows:

operator typename(){….}

The above function shall convert a class type data to typename.
A conversion function must follow the following 3 rules:
a. It cannot have a return type
b. It has to be declared inside a class.
c. It cannot have any arguments.

(ii)File pointers: we need to have file pointers viz. input pointer and output pointer. File pointers are required in order to navigate through the file while reading or writing. There are certain default actions of the input and the output pointer. When we open a file in read only mode, the input pointer is by default set at the beginning. When we open a file in write only mode, the existing contents are deleted and the file pointer is attached in the beginning. C++ also provides us with the facility to control the file pointer by ourselves. For this, the following functions are supported by stream classes: seekg(), seekp(), tellg(), tellp().

(iii) Function prototyping is used to describe the details of the function. It tells the compiler about the number of arguments, the type of arguments, and the type of the return values. It some what provides the compiler with a template that is used when declaring and defining a function. When a function is invoked, the compiler carries out the matching process in which it matches the declaration of the function with the arguments passed and the return type. In C++, function prototype was made compulsory but ANSI C makes it optional. The syntax is as follows:

type function-name(argument-list);

example: int func(int a, int b, int c);

(iv)Overload

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Quiz Comp Archi

    • 438 Words
    • 3 Pages

    12) Please list registers and their functions in ARM. How many general purpose registers and how to use them in the program?…

    • 438 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Comp 220

    • 1463 Words
    • 6 Pages

    Pointers also have the requirement that the pointer type must be of the same data type as the variable, or the data that it points to or holds the address of. The power of pointers also hints at the potential complexity of their use, which is why this lab is focused almost entirely on several different aspects and uses of pointers. The lab also introduces pointer arrays and pointers to pointers.…

    • 1463 Words
    • 6 Pages
    Good Essays
  • Satisfactory Essays

    9.) A bug collector collects bugs every day for 7 days. Design a program that keeps a running total of the number of bugs collected during the 7 days. The loop should ask for the number of bugs collected each day, and when the loop is finished, the program should display the total number of bugs collected.…

    • 651 Words
    • 4 Pages
    Satisfactory Essays
  • Powerful Essays

    EAS230Syllabus

    • 1748 Words
    • 8 Pages

    C++ programming: editing, compiling, user I/O, variables (ints, doubles, char, strings, booleans), loops, decisions, functions, pointers, arrays, tables, databases, sorting.…

    • 1748 Words
    • 8 Pages
    Powerful Essays
  • Satisfactory Essays

    CS305 Final Exam Questions

    • 1044 Words
    • 6 Pages

    1. (D) Which of the following CALL instructions writes the contents of EAX to standard output as a signed decimal integer?…

    • 1044 Words
    • 6 Pages
    Satisfactory Essays
  • Satisfactory Essays

    It/210 Course Design

    • 2571 Words
    • 11 Pages

    Explain how a structured approach relates to developing programs and why using an organized approach is important. Course Design Guide IT/210 Version 5 CheckPoint Input Data and Output Process Resources: Appendix B, Appendix C Read the following scenario: You want to build a program that will keep track of your CD and DVD collection at home. Use the table in Appendix C to complete this CheckPoint.…

    • 2571 Words
    • 11 Pages
    Satisfactory Essays
  • Good Essays

    It-250 Week 5 Questions

    • 397 Words
    • 2 Pages

    A: transactions.c and reports.c are compiled to produce an executable file named accts –ctransactions.c o transactions.o -c reports.c –o reports.o transactions.o reports.o –o my…

    • 397 Words
    • 2 Pages
    Good Essays
  • Good Essays

    All data-input and data-display operations (cin and cout) should be done in the function main() test program.…

    • 477 Words
    • 2 Pages
    Good Essays
  • Better Essays

    E-Commerce Exercise

    • 1068 Words
    • 5 Pages

    1. Why do you think Java provides primitive data types AND wrapper classes for them? Why not just one or the other?…

    • 1068 Words
    • 5 Pages
    Better Essays
  • Good Essays

    it320 assignment 1-3

    • 1779 Words
    • 8 Pages

    9. A student writes a report using a word processor, saving the report in a file called my_report. The student stores the file on his laptop hard disk drive. Later, he posts the file on a file-sharing site for a classmate to review the report. Then, he copies an updated version of the file to a flash drive to submit it to his instructor. Which of the following are some of the important features supplied by files defined by a computer OS? ()…

    • 1779 Words
    • 8 Pages
    Good Essays
  • Good Essays

    8. The Pythagorean Theorem states that the sum of the squares of the sides of a right triangle is equal to the square of the hypotenuse. For example, if two sides of a right triangle have lengths 3 and 4, then the hypotenuse must have a length of 5. The integers 3, 4, and 5 together form a Pythagorean triple. There is an infinite number of such triples. Given two positive integers, m and n, where m > n, a Pythagorean triple can be generated by the following formulas:…

    • 631 Words
    • 3 Pages
    Good Essays
  • Good Essays

    C++ Lab Session

    • 868 Words
    • 4 Pages

    Given the following classes, write the implementation codes and the driver program to demonstrate inheritance using C++. You may add other appropriate member functions and / or data members.…

    • 868 Words
    • 4 Pages
    Good Essays
  • Good Essays

    C+++ Basic Lessons

    • 711 Words
    • 3 Pages

    The predefined object cout is an instance of ostream class. The cout object is said to be "connected to" the standard output device, which usually is the display screen. The cout is used in conjunction with the stream insertion operator, which is written as << which are two less than signs as shown in the following example.…

    • 711 Words
    • 3 Pages
    Good Essays
  • Good Essays

    bca qstn

    • 1776 Words
    • 8 Pages

    5. In switch case statement , every case should have a ------------ statement as the last…

    • 1776 Words
    • 8 Pages
    Good Essays
  • Good Essays

    Inheritance and Polymorphism Prepared by: Prof. Irysh Paulo R. Tipay, MSCS Quote for the Day  “That's the thing about people who think they hate computers. What they really hate is lousy programmers.” ― Larry Niven Recap!…

    • 1037 Words
    • 18 Pages
    Good Essays