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

Question #45336
write a c++ program using class to input marks and print it
1
Expert's answer
2014-08-26T06:51:20-0400
#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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS