Public data members and private data members.

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

 Explain the difference between public data members and private data members. Give an example in the main function to show that one C++ statement is valid and the other is invalid (you can use Grade class in Problem 5.

 

2        What output would be produced by the following program?

#include <iostream>

using std::cout; using std::endl;

int main()

{

      int a[] = {3, 1, 0, 2, 4};

   int b[] = {50, 40, 30, 20, 10};

   for (int i=0; i<5; i++}

cout << b[ a[i] ] << endl;

   return 0;

     }

 

3        The following code has many errors. Please point out and correct them.

#include <iostream>

using namespace std;

class Date

{

public

      Date()

      {

month = day = 0;

}

      setDate(int m, int d)

      {

            month = m;

            day = d;

}

      int getDay();

{

            return day

}

private

int month, day;

}

 

int main()

{

      Date d;

      setDate(10,20);

      cout << getDay() << endl;

      return 0;

}

 

4        What output would be produced by the following program?

.........................

int main()

{

   ifstream fin;

   fin.open("list.dat");

   int count = 0;

   double next, total=0.0;

   cout << fixed << setprecision(2);

   while (fin >> next)

   {

     count++;

     total += next;

     cout << setw(7) << next << endl;

        }

        fin.close();

        cout << "The sum of " << count << " numbers is "

             << total << endl;

   return 0;

}

The file list.dat contains the following five numbers (and nothing more):

10.0001 1.1e2      1.0e-6

5.0007   -5.0008

 

 

Reference no: EM13167086

Questions Cloud

Write a program in which a ball is released : Write a program in which a ball is released from a user-defined height and free-falls to the ground. The ball is pulled by earth's gravity of 9.8 m/sec 2 . Assume that each pixel represents 1 cm. Once the ball hits the ground
For each of these four modifications : For each of these four modifications, compute and graph the effects on the original system. Explain in words the effect when the multiprogramming level, N , is small and when N is large.
C program to mips program : Convert the following C program to MIPS program. Assuming that i, j, k, f, are stored in registers $s0, $s1, $s2, $s3 already.
Python program that reads in a series of positive integers : Write a Python program that reads in a series of positive integers and writes out theproduct of all the integers less than 25 and the sum of all the integers greater than or equal to 25. Use 0 as a sentinel value
Public data members and private data members. : Explain the difference between public data members and private data members. Give an example in the main function to show that one C++ statement is valid and the other is invalid (you can use Grade class in Problem 5.
The goal of this project is to create : The goal of this project is to create a simple command line program that reads in a single word from the command line (use the "int argc, char * argv[]" approach discussed in class and in previous projects) and stores the unique letters of that wo..
Write a program that reads an array with wind-tunnel test : write a program that reads an array with wind-tunnel test data then allowss the user to enter a flight-path angle. If the angle is within the bounds of the data set, the program should then use linear inteerpolation to compute the corresponding coeff..
Generate a two-dimensional array : Generate a two-dimensional array of integers of 10 rows by 10 columns that contains 100 random numbers between 0 and 9. Print out the array (well formatted) and do the following computations
End to end encryption : How is end to end encryption different from other types of encryption? At what layer does it take place?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a very basic doubly-linked list

CptS 122 Lab #2: Linked Lists ,  Along with vectors, linked lists are one of the fundamental data structures in computer science. Unlike vectors, which store information in a contiguous block of computer memory, linked lists have the potential to sto..

  Two for loops that will calculate the sum of all even number

Write a program using two for loops that will calculate the sum of all even numbers between 2 and 100,

  During the execution of the above code, how many instru

(a) During the execution of the above code, how many instructions are executed? (b) Assuming a standard unicycle machine (CPI = 1) running at 100 KHz, how long will the above code take to complete?

  Write a function template square()

Write a function template Square() that returns the square of its only argument.

  Write a program to analyze students course marks

Write a program to analyze students course marks. The program should read in students course marks from "m2-grading.txt". The data file has a headline including students ID#, course-1marks, course-2 marks and course-3 markes.

  The reverse of each word, and a palindrome checker

give us the first letter of each word, the first half of each word, the reverse of each word, and a palindrome checker to see if the word is a palindrome.

  Draws a pyramid consisting of bricks

Write a C program that draws a pyramid consisting of bricks arranged in horizontal rows, so that the number of bricks in each row decreases by one as you move up the pyramid.

  How nested if-statements replace with one if-statement

Describe how following nested If-statements could be replaced with one if-statement using logical operator (And/Or/Not). Write down the C++ code example.

  Write a menu driven program for an online beef

Write a menu driven program for an online beef distribution company. There are 8 different

  Write a function that accepts an int array

The task calls for: Write a function that accepts an int array and the array's size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer t..

  Write a program to calculate a person''s net pay

Write a program to calculate a person's net pay after subtracting federal income tax.The program should ask the user to enter the person's name, social security number, gross pay, and the number of dependents.

  A hierarchical jpeg encode decoder for greyscale images

This project is to develop a program that implements a hierarchical JPEG encoder/decoder for greyscale images.

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