I need help writing some of this code using C++ language . Step 1 The Char Type
ID: 3848119 • Letter: I
Question
I need help writing some of this code using C++ language.
Step 1 The Char Type Create a complex type called Char that models the primitive type char. In your class you are going to want to have the following constructors: Java Description Char0 Char0 Default constructor that sets the data section of the class to null (binary 0) overloaded constructor that takes a primitive char as an argument. It should set the data Char (char c) Char(char c) section of the class to the argument. Char(int c) Chamant Overloaded constructor that takes a primitive int as a parameter. The data section of the c) class should be set as a character from the argument. Char(const Char(inal overloaded constructor that takes the complex Char type as a parameter. The data section Char &c;) Char c) of the class should be set with the data section of the argument Char(string Char (String overloaded Constructor that takes a string type as a parameter The data section of the class should be set to the first character in the string. Your class should have the following mutators.Explanation / Answer
I did not understand documentation of all functions. I did my best to answer.
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;
class Char{
public:
char data;
Char();
Char(char c);
Char(int c);
Char(const Char &c);
Char(string c);
void equals(const Char &c);
void equals(char c);
void equals(int c);
char toChar() const;
int toInt() const;
string toString();
string toHexString();
string add(char c);
string add(const Char &c);
};
Char::Char(){
data='';
}
Char::Char(char c){
data=c;
}
Char::Char(int c){
data=(int)c;
}
Char::Char(const Char &c){
data=c.data;
}
Char::Char(string c){
data=c[0];
}
void Char::equals(const Char &c){
data=c.data;
}
void Char::equals(char c){
data=c;
}
void Char::equals(int c){
data=(char)c;
}
char Char::toChar() const{
return data;
}
int Char::toInt() const{
return (int)data;
}
string Char::toString(){
string str="a";
str[0]=data;
return str;
}
string Char::toHexString(){
char *l_pCharRes = new (char);
itoa((int)data,l_pCharRes,16);
return l_pCharRes;
}
string Char::add(char c){
string str="ab";
str[0]=data;
str[1]=c;
return str;
}
string Char::add(const Char &c){
string str="ab";
str[0]=data;
str[1]=c.data;
return str;
}
class BigDecimal{
public:
vector<Char> data;
BigDecimal();
BigDecimal(string value);
void equals(char ch);
void equals(string value);
double toDouble();
Char at(int index);
string toString();
};
BigDecimal::BigDecimal(){
Char data1('0');
Char data2('.');
Char data3('0');
data.push_back(data1);
data.push_back(data2);
data.push_back(data3);
}
BigDecimal::BigDecimal(string value){
int i=0;
while(value[i]!=''){
Char c(value[i]);
data.push_back(c);
i++;
}
/*for(i = 0; i < 3; i++){
cout << data[i].toChar() << endl;
}*/
}
void BigDecimal::equals(char ch){
if(ch >= '0' && ch <= '9')
data[0].equals(ch);
}
void BigDecimal::equals(string value){
//if(isdigit(ch))
//data[0].equals(value);
}
double BigDecimal::toDouble(){
}
Char BigDecimal::at(int index){
return data[index];
}
string BigDecimal::toString(){
int size=data.size();
char str[size];
int i=0;
for(i=0;i<size;i++)
str[i]=data[i].toChar();
return str;
}
int main(){
Char c1("str");
Char c;
c.equals(65);
cout << c.add(c1) <<endl;
BigDecimal bg("sar");
return 0;
}