Write a class with one virtual and one non-virtual function

Assignment Help C/C++ Programming
Reference no: EM131220604

Please use codeblocks

List the program and the output on the command line

Eg

#include <iostream>

#include <vector>

using namespace std;

int main()

{

floatjohno = 0.5;

size_t size = 24;

vector<float> array(size);

for(inti=0; i<size; ++i)

    {

johno = johno + 1;

array[i] = johno;

cout<<johno;

cout<< " ";

}

}

564_Untitled.png

Q1

Write a class with one virtual function and one non-virtual function. Inherit a new class, make an object of this class, and upcast to a pointer of the base-class type. Use the clock( ) function found in <ctime> to measure the difference between a virtual call and non-virtual call. You'll need to make multiple calls to each function inside your timing loop in order to see the difference.

Q2

Create two classes called Traveler and Pager without default constructors, but with constructors that take an argument of type string, which they simply copy to an internal string variable. For each class, write the correct copy-constructor and assignment operator. Now inherit a class BusinessTraveler from Traveler and give it a member object of type Pager. Write the correct default constructor, a constructor that takes a string argument, a copy-constructor, and an assignment operator.

Q3

Create two identical functions, f1( ) and f2( ). Inline f1( ) and leave f2( ) as an out-of-line function. Use the Standard C Library function clock( ) that is found in <ctime> to mark the starting point and ending points and compare the two functions to see which one is faster. You may need to make repeated calls to the functions inside your timing loop in order to get useful numbers.

Q4

Create a Text class that contains a string object to hold the text of a file. Give it two constructors: a default constructor and a constructor that takes a string argument that is the name of the file to open. When the second constructor is used, open the file and read the contents into the string member object. Add a member function contents( ) to return the string so (for example) it can be printed. In main( ), open a file using Text and print the contents.

Q5

Create a Hen class. Inside this, nest a Nest class. Inside Nest, place an Egg class. Each class should have a display( )member function. In main( ), create an instance of each class and call the display( )function for each one.

Q6

Write a function that takes a char* argument. Using new, dynamically allocate an array of char that is the size of the char array that's passed to the function. Using array indexing, copy the characters from the argument to the dynamically allocated array (don't forget the null terminator) and return the pointer to the copy. In your main( ), test the function by passing a static quoted character array, then take the result of that and pass it back into the function. Print both strings and both pointers so you can see they are different storage. Using delete, clean up all the dynamic storage.

Q7

Create a vector<float> and put the following 25 floating-point numbers into it using a for loop:

0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5 10.5 11.5

12.5 13.5 14.5 15.5 16.5 17.5 18.5 19.5 20.5 21.5

22.5 23.5 24.5

 

Reference no: EM131220604

Questions Cloud

Recursive method written by you or taken from web : What elements should be considered to be included in any recursive method? Discuss these elements using an example (code required) of a recursive method written by you or taken from Web. Try choosing one different from that of any posted thus far.
National credit bureaus collect information on peoples : Suppose that a new privacy law makes it illegal for credit bureaus to collect this information. - What effect would this have on the banking industry?
Description of the network technologies and components : Prepare a Word document that is approximately 3-5 pages in APA format. It should be professional in appearance and suitable for review by network novices. Present the information in laymen's terms.
What happens to a cfl when it is encoded : What happens to a CFL when it is encoded? Is it still necessarily contextfree? (Of course you are supposed to provide an algorithm to construct the grammar if the answer is yes and to provide an example if the answer is no.)
Write a class with one virtual and one non-virtual function : Write a class with one virtual function and one non-virtual function. Inherit a new class, make an object of this class, and upcast to a pointer of the base-class type. Use the clock( ) function found in to measure the difference between a virtual ..
Identify why obesity is considered to be a health risk : Define obesity and identify why it is considered to be a health risk. Identify and discuss one feedback system from either sex and identify the hormones and structures/organs involved.
Which two organs do the oviducts effectively connect : Which two organs do the oviducts effectively connect? In males where specifically are androgens produced? What function is performed by the seminiferous tubules? Name the primary sex organs (gonads) for males and females.
Explain the difference between innate and adaptive immunity : Explain the difference between innate and adaptive immunity. Identify one physical and one chemical barrier of the body to infectious pathogens. What type of white blood cells may become pus following response to an infection?
How are indirect costs involved in the preparation : What are the differences in the ways project managers, accountants, and financial comptrollers perceive the expenses of a project? How are indirect costs involved in the preparation of the budget for a project?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Class scope variables-helper methods

Design a C# Windows Application to compute the cost of manufacturing different objects. The object can be a cylinder, a cone or a prism with the equilateral triangular base. The user should enter the radius of the base (or the side of the base for..

  Prompts the user to enter an integer

Write the code that prompts the user to enter an integer between 1 and 20 (including 1 and 20), reads the value using cin, and then prints the value that they entered in a statement that begins with "You entered a ". Save this version in a separate l..

  Can you find a bug in this program

Can you find a bug in this program and then fix it so that it won't have an infinite loop?

  Difference between connectionless and connection-oriented

How does SSH differ from Telnet? How does HTTPS differ from HTTP?

  Explain how is the syntax for a class in c similar to the

how is the syntax for a class in c similar to the syntax for structures in c? use this syntax to create your own

  Write a recursive function to draw the pattern

write a program that prompts the user to enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as the number of lines generates the above pattern.

  Enter the temperature at noon of each of the five days

Write a program that allows each employee to enter the temperature at noon of each of the five days and displays the highest, lowest, and average (mean) temps.

  How many times is copy constructor called in the given code

How many times is the copy constructor called in the given code. Why are the parentheses needed in the expression (*p).data?

  Write c program-visual studio to scan multiple text files

Write program in C or C++ and Visual Studio to scan multiple text files and count number of occurrences of each word in those files. Use binary tree to keep track of all words.

  Implement a simple calculator program

Implement a simple calculator

  Create a permutation generator script for us

create a permutation generator script for us that will generate all the permutations possible from a set of words. The script can be written in PHP, jscript, Python or Java.

  Write a pseudocode function in terms of adt appointment

Write speci?cations for a method within Date that advances any given date by one day. Include a statement of purpose, the preconditions and postconditions, a description of the arguments, and a description of any return value.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd