60 678
Assignments Done
97,7%
Successfully Done
In April 2018

Answer to Question #45336 in C++ for susmita singh

Question #45336
write a c++ program using class to input marks and print it
Expert's answer
#include <iostream>
#include <vector>
class PrintMarks {
private:
  std::vector<int>* marks;
  void printMarks() {
std::cout << "Printing marks" << std::endl;
for ( int i = 0; i < marks->size(); i++ ) {
std::cout << marks->at(i) <<  " ";
}
  }
public:
  PrintMarks() {
this->marks = new std::vector<int>();
  }
  ~PrintMarks() {
delete marks;
  }
  void inputMarks() {
std::cout << "Please input marks.-1 would mean that you're done entering the sequence." <<std::endl;
for ( ; ;) {
int input = 0;
std::cin >>input;
if ( input == -1 ) {
  break;
}
marks->push_back(input);
}
this->printMarks();
  }
};
int main() {
PrintMarks *tryIt = new  PrintMarks();
tryIt->inputMarks();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions