Create a simple main function to test your class.

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

C++ Study Examples - Data Abstraction

1. Explain the problem with the following code segments:

a. int *x;
    *x = 5;
b. const int * x;

2. Consider the following code:

 int nums[10] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
 int *pInt;
 pInt = &nums[2];
 pInt += 2;
 *pInt = 20; 

What will be the resulting array when this code is completed?  Explain.

3. Consider the following code:
 int i;
 int smallest;
 int nums[5] = {4, 20, 18, 7, 2};
 
 smallest = nums[0];
 for (i = 1; i < 5; i++) {
        if (nums[i] < smallest) smallest = nums[i];
}
cout << smallest;

a. Rewrite the code using pointers.  Specifically, instead of i and smallest, use
 
int* pInt;
int* pSmallest;

b. Which version of the code do you find easier to read?

4. Take the multi-purpose sorting program that uses function pointers.  Create a new auxiliary function such that the routine will sort numbers in ascending order, but all zeros will be placed at the end of the list. For example, an array with 3, 0, -5, 9, 22, 0, 14, 7 would be set to -5, 3, 7, 9, 22, 0, 0.

5.  Create a StudentGrade class that includes two data members: a student ID number and the student's score on a test. Both of these are integers.  Include "get" and "set" member functions for each of the data members, plus a displayRecord method which outputs the values in this form:

Student 12345 has a score of 98 For this program you do not have to do any data validation in the "set" methods. In addition to the class, write a short main function that tests your class.

6. Modify your StudentGrade class such that the "set" methods perform data validation.A student ID should be in the range of 10000-50000, and a grade should be in the range 0 - 100. Use a single "if" statement (using the && operator) in each "set" method.

7. Create a BaseballBatter class that records the batting statistics for an individual player.It should have "get" and "set" methods for the following values: at-bats, singles, doubles, triples, and home runs. The "set" methods should check that only non-negative values are set.In addition, the class should have the following methods:

a. A validData method that returns true if the number of at-bats is greater than the number of hits.

b. A battingAverage method that returns the batting average.

c. A sluggingPercentage method that returns the slugging percentage.

Create a simple main function to test your class.

 

Reference no: EM13936815

Questions Cloud

How is social media impacting firms individuals and society : How do recent changes in computing impact consumers? Are these changes good or bad? Explain. How do they impact businesses? How is social media impacting firms, individuals, and society
Use appropriate classes, fields, methods, objects : The summary information required by the University is the number of students and guests at each ceremony the total number of students and guests at all three ceremonies the ratio of students to guests at each of the three ceremonies.
Ppportunities does the existence of the buffett community : How can we consider Jimmy Buffett fans as members of a reference group? A brand community? 2 Refer to your responses to question 1. What kind of opportunities does the existence of the Buffett community.
Car hire database including appropriate data : This assignment prepares you for the examination and you should consider each hour devoted to the assignment as an hour devoted to exam preparation.
Create a simple main function to test your class. : Create a BaseballBatter class that records the batting statistics for an individual player.It should have "get" and "set" methods for the following values: at-bats, singles, doubles, triples, and home runs. The "set" methods should check that only..
Book summary - the dead do not improve : Please write a summary of BOOK ONE (pg 1-60) of "The Dead Do Not Improve" by Jay Caspian Kang
Is noailles being unfairly penalised if she implements jit : Is Noailles being unfairly penalised if she implements JIT? What should Noailles do? What should Eluard do? Is Noailles correct in characterising some of the financial benefits as 'soft'?
Including the column names, datatypes : Please submit the CODE and OUTPUT for all programming questions. You will submit this assignment electronically in the ASSESSMENT area of the Study Desk.
Conduct research into identifying international markets : Why is it important to conduct research into identifying international markets?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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