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

  Write the cpp code for controversial issue of global warming

Write the C++ code for controversial issue of global warming has been widely publicized by the film An Inconvenient Truth, featuring former Vice President Al Gore.

  Compute the volume of write-back traffic in bytes

Compute the volume of write-back traffic in bytes. Provide a plot of the miss rate vs. the line size for line sizes of 32 bytes to 2 Kbytes. Note that line sizes are a power of 2.

  Prepare a program for sorting the numbers

Write a program that orders three double numbers by increasing value. The program should include a function named sort3 that takes three double * arguments (pointer to double). The function prototype is void sort3(double *x, double *y, double *z);

  Application shows a user friendly message

The software fails to respond to user inputs, if there is a connectivity problem with the database. Add the code snippet that the development team should use to ensure that the application shows a user- friendly message, if such a situation arises..

  Determine the position in the x-y plane

Every circle has a center and a radius. Given the radius, we can determine the circle's area and circumference. Given the center, we can determine the position in the x-y plane.

  Take four unsigned char bytes and combine

Take four unsigned char bytes and combine them into a single integer type. You will needed shifts and one of the logical bit operators.

  Object oriented programming paradigm is better choice

Explain why object oriented programming paradigm is considered better choice than structured programming paradigm. Does it reflect our "natural" way of thinking or do you find it artificial?

  What is wrong with this function

What is wrong with this function? Can you find problem in this code?

  C write a function which adds the two numbers

1. In C write a function which adds the two numbers. Test this function by calling from the main. In main, the user should be asked to provide the two numbers.

  Program that will ask for a month

Write a program that will ask for a month (1-12) and a year (yyyy). the program should then produce a calendar showing the month name and year and have all of the days displayed under it.

  Where can grep be found for windows for linux

What is grep? Where can grep be found for Windows? For Linux?

  Where may the class be accessed

What is an object's lock and which object's have locks? If a class is declared without any access modifiers, where may the class be accessed?

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