Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**Programs must be able to run in Ubuntu 1. (35 pts) Write a C++ program A4p2.cpp with a class of your own design. The class

**Programs must be able to run in Ubuntu

1. (35 pts) Write a C++ program A4p2.cpp with a class of your own design. The class should contain a protected int member variable var, which is initialized with an integer value between 1 and 50 in a constructor that takes an integer parameter. The class should contain a public member function called play that should print out a sequence of integers as a result of iteratively applying a math function f to the member variable var together with the length of this sequence. The function f is defined as f(x)=(3x+1)/2 if x is odd and f(x)=x/2 if x is even. Stop the iteration when the value 1 is reached. (Example: When var is 6, the play functions output sequence should be 6,3,5,8,4,2,1 and the length of this sequence is 7.) In your main function create an object of this class whose member var should be initialized through constructor with the first command line argument to your program (i.e., argv[1]) and then call the playmember function on the object. You can check whether the supplied first command line argument is an integer between 1 and 50 in your main function. A sample run can look like the following. Submit source code A4p2.cpp and you dont need to submit a screen shot.

[kwang@computer][~/temp]$./A4p2 6

6 3 5 8 4 2 1

Length of the sequence: 7

  1. (35 pts) Write a C++ program A4p3.cpp with a class that is a derived class of your class from problem Add a private intmember variable var2 to this class. Initialize the member variables var and var2 with values between 1 and 50 using a constructor that takes two integer parameters. Add a public member function called getsp that should print out the sum and product of var and var2. In your main function, create an object of this class, initialize its members var and var2 through constructor with the first two command line arguments to your program (i.e., argv[1] and argv[2]) and then call the play and getsp member functions on the object. A sample run can look like the following. Submit source code A4p3.cpp and you dont need to submit a screen shot. Please do NOT just submit A4p3.cpp because it seems to include all functionality of A4pcpp. You need to submit two separate program source files.

[kwang@computer][~/temp]$./A4p3 6 8

Iterated integer sequence for 6 is:

6 3 5 8 4 2 1

Length of the sequence: 7

Sum of 6 and 8 is 14. Product of 6 and 8 is 48.

You need to supply a single makefile to compile your programs in both problems 2 and 3. Do not combine programs 2 & 3 into one program just because they share some parts.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899