- #1
diredragon
- 323
- 15
Homework Statement
I am quite new to C++. I have completed my C course and am now taking a C++ course at my college. The first problem i encountered is with classes and custom made constructors. In the first part of the problem I am supposed to create a class with a field which is a dynamic char array for storing numbers like decimal ones. I am also forbidden to use anything but <iostream>. Here is the problem:
Create a class called Number which stores numbers in a dynamic array (number can be a decimal number) in a way that one digit is one array place. Number of digits is not limited. Implement the constructors Numbers::Numbers(char* nms); and Number::Number(int* part1, int* part2);, where part1 is left of the . and part2 right of the .
Homework Equations
3. The Attempt at a Solution [/B]
Code:
#include <iostream>
using namespace std;
class Number {
char* numarr;
public:
Number(char* nms) {
numarr = nms; //Can i do this or do i need to know the length of nms and then allocate numarr?
}
Number(int* part1, int* part2) {
//This is the hard part for me. How do i insert integers into an array digit by digit? Do i convert them to strings?
}
};