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

  Explain the concept of arrays

n array is a powerful data structure in C++ that lets us keep track of lists of different types of information. They are quite flexible in that we can put almost anything we want into an array and then access it at a later time. Arrays have two ma..

  Inventory items stored in Sudbury

Give the details of all suppliers in the Sault Ste Marie, list all inventory items with a quantity less than 100 units and list all the inventory items stored in Sudbury

  That reads ten numbers from input and prints

Write a C program that reads ten numbers from input and prints them in reverse order. We assume that the data consists of integers. The program should conform to the following format

  Compcets of office apps

Cell Reference is the location of a cell. Cells are located in columns marked by letters, and rows are marked by numbers. Example to reference a cell in column D row 10 you would reference it as D10.

  Inheritance and output formatting

Inheritance and Output Formatting, finish the implementation of class name and derived classes person and employee in the following code. Format the output neatly using setw() and or other setioflags features

  An arithmetic expression

The statements of that expression language consist of an arithmetic expression followed by a list of assignments. Assignments are separated from the expression and each other by commas. A semicolon terminates the expression. The arithmetic expr..

  How will you do the shrink operation

How will you do the shrink operation and how will you do the expand operation -

  Farey fractions of level one

Write a program that for a number n entered by the user creates-by constantly extending it-a linked list of fractions at level n and then displays them.

  What is the c++ statement responsible for the output display

What is the C++ statement responsible for the output display and add the new display statement to the existing program requesting ENTER EMPLOYEE ID. Compile and run your program.

  Extension of a filename

Modify your earlier program that found the extension of a filename. This time your program will identify a file name that is no longer that 12 characters and has one of five extensions that you specify (eg: .doc. .py, .html, .txt, .ps).

  Make a program to play lottery

make a program to play lottery. The program randomly generates a Lottery of a three-digit number( any number from 100 to 999), prompts the user to enter a three-digit number, and determines

  Determine the meaof the numbers in the array

Determine the mean(average) of the numbers in the array, and output the reslt. Use a subprogram to input the numbers, a function to find the mean.

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