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

  Features with the real life scenarios

Explain any three features that must be implemented by the application that will be created by WebSoft Solutions Pvt. Ltd. Support your answer with suitable examples. Relate the features with the real life scenarios.

  Write c program that will input two values from the user

write c program that will input two values from the user with a prompt ? that are a value and a base with which you

  Change temperature fahrenheit to celsius and kelvin

Write a program in c++ that takes the temperature in Fahrenheit and convert it to Celsius And Kelvin:

  Write a c program generates a ordered sequence of random num

Write a C program Gen.c that generates a ordered sequence of 20 random numbers within a range of 1000 to 9999. The program is invoked by a command line % gen datfile1

  How can we definean instance of this class

How can we definean instance of this class?

  Industry standards in configuration management and control

Information related to configuration management and preventative maintenance. Industry standards in configuration management and control. Training approaches to allow for adaptive maintenance and confidence.

  Sales commission file contains

A transaction record on a sales commission file contains the retail price of an item sold, a transaction code that indicates the sales commission category to which an item can belong, and the employee number of the person who sold the item.

  Rewrite the overloaded input operator for the ratio class

Rewrite the overloaded input operator for the Ratio class so that, instead of prompting for the numerator and denominator, it reads a fraction type as "22/7".

  Write a value-returning function

Write a program that uses the function isNumPalindrome given(Palindrome Number). Test your program on the following numbers: 10, 34, 22, 333, 678, 67876, 44444, and 123454321.

  Implements the postfix evaluation algorithm

Write a program that implements the postfix evaluation algorithm that is on your course module.your program should enable users to enter the postfix expression and output the result of evaluation to screen.

  Windows application that function like a banking account

Create a Windows application that function like a banking account register. Separate the business logic from the presentation layer. The graphical user interface should allow user to input the account name, number, and balance.

  Consider the following nested loop construct

Consider the following nested loop construct. Categorize its efficiency in terms of the variable n using big-O notation. Suppose the statements represented by the ellipsis require four main memory accesses (each requiring one microsecond) and two dis..

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