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

  • 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
  • Satisfactory Essays

    It/210 Course Design

    • 2571 Words
    • 11 Pages

    Reading Read Ch. 3 of Prelude to Programming. Reading…

    • 2571 Words
    • 11 Pages
    Satisfactory 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
  • 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

    Assignment 3 CS 113

    • 804 Words
    • 5 Pages

    2. Problem 2: Program listing with the program output using the input in file Data3.txt…

    • 804 Words
    • 5 Pages
    Good Essays
  • Good Essays

    2. Briefly describe two operations that a debugger can perform (i.e., commands that you can give to a debugger? What two things does the compiler do to assist a debugger?…

    • 567 Words
    • 3 Pages
    Good Essays
  • Good Essays

    C++ Midterm

    • 2831 Words
    • 12 Pages

    What is the value inside the "value" variable at the end of the given code snippet?…

    • 2831 Words
    • 12 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+++ 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

    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

    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
  • 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