C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[64458] 간단한 프로그램인데 string하는부분 오류좀 잡아주세요 ㅠㅠ
K [] 935 읽음    2011-05-29 07:14




간단한 프로그램인데 이상한 오류때문에 되질 않네요..
주의해서 보셔야할 곳이 convertToMultitap() 함수랑 overload << 함수에요

에러좀 잡아주세요 :)

파일은 3개구여 메인보시면 어떤 답이 출력되야되는지 나와있구요

지금 현재 디버그해본결과 convertToMultitap 함수안에서

convert[a] = '숫자' 이렇게 입력하는게 안되거든요.. 부탁드립니다 :)

참.. 여기만든 함수들 그대로 유지시키고 하는게 좋고요 함수및 변수추가는 가능합니다..

!!!!!!!!!! 오류만 꼭좀 잡아주세요 제가 아직 string 하는부분이 익숙치않아서 그런거같은데
간단한 설명두 해주시면 감사하겠습니다!!


--------------------------원본 질문---------------------------------


Multitap refers to the early text entry system for mobile phones based on the standard telephone keypad. The alphabet is printed under each key (beginning on "2") in a multi-letter sequence as follows; ABC under 2 key, DEF under 3 key, etc. The system is used by repeatedly pressing the same key to cycle through the letters for that key. For example, pressing the "3" key twice would indicate the letter "E".




Based on the following class diagrams, create a class which converts text into its equivalent form in Multitap, as if you were texting on an older cellphone.







--------------------------Multitap.h----------------------------





#ifndef MULTITAP_H

#define MULTITAP_H




#include <iostream>

#include <string>

#include <cstdlib>

using namespace std;




class Multitap {

public:

Multitap();




void setString( string value );

void setCString( char * value );

void clear();

string convertToMultitap();

string getString();




friend ostream& operator <<( ostream& outs, Multitap & m );

private:

string myString;

};




#endif







---------------------------Multitap.cpp------------------------------





//This is the part of class declaration...




#include "Multitap.h"




Multitap::Multitap() {

myString.clear();  // clear string

}




void Multitap::setString(string value) {

myString = value;

}




void Multitap::setCString(char* value) {

myString = value;

}




void Multitap::clear() {

myString.clear();

}




string Multitap::convertToMultitap() {

int a = 0;

string converter;

converter.clear();




for(int i = 0; i < (int) myString.length(); i++) {




if (myString[i] == 'A' || myString[i] == 'a') {

converter[a] = '2';

a += 1;

}

else if (myString[i] == 'B' || myString[i] == 'b') {

converter[a] = '2';

converter[a+1] = '2';

a += 2;

}

else if (myString[i] == 'C' || myString[i] == 'c') {

converter[a] = '2';

converter[a+1] = '2';

converter[a+2] = '2';

a += 3;

}

else if (myString[i] == 'D' || myString[i] == 'd') {

converter[a] = '3';

a += 1;

}

else if (myString[i] == 'E' || myString[i] == 'e') {

converter[a] = '3';

converter[a+1] = '3';

a += 2;

}

else if (myString[i] == 'F' || myString[i] == 'f') {

converter[a] = '3';

converter[a+1] = '3';

converter[a+2] = '3';

a += 3;

}

else if (myString[i] == 'F' || myString[i] == 'f') {

converter[a] = '3';

converter[a+1] = '3';

converter[a+2] = '3';

a += 3;

}

else if (myString[i] == 'G' || myString[i] == 'g') {

converter[a] = '4';

a += 1;

}

else if (myString[i] == 'H' || myString[i] == 'h') {

converter[a] = '4';

converter[a+1] = '4';

a += 2;

}

else if (myString[i] == 'I' || myString[i] == 'i') {

converter[a] = '4';

converter[a+1] = '4';

converter[a+2] = '4';

a += 3;

}

else if (myString[i] == 'J' || myString[i] == 'j') {

converter[a] = '5';

a += 1;

}

else if (myString[i] == 'K' || myString[i] == 'k') {

converter[a] = '5';

converter[a+1] = '5';

a += 2;

}

else if (myString[i] == 'L' || myString[i] == 'l') {

converter[a] = '5';

converter[a+1] = '5';

converter[a+2] = '5';

a += 3;

}

else if (myString[i] == 'M' || myString[i] == 'm') {

converter[a] = '6';

a += 1;

}

else if (myString[i] == 'N' || myString[i] == 'n') {

converter[a] = '6';

converter[a+1] = '6';

a += 2;

}

else if (myString[i] == 'O' || myString[i] == 'o') {

converter[a] = '6';

converter[a+1] = '6';

converter[a+2] = '6';

a += 3;

}

else if (myString[i] == 'P' || myString[i] == 'p') {

converter[a] = '7';

a += 1;

}

else if (myString[i] == 'Q' || myString[i] == 'q') {

converter[a] = '7';

converter[a+1] = '7';

a += 2;

}

else if (myString[i] == 'R' || myString[i] == 'r') {

converter[a] = '7';

converter[a+1] = '7';

converter[a+2] = '7';

a += 3;

}

else if (myString[i] == 'S' || myString[i] == 's') {

converter[a] = '7';

converter[a+1] = '7';

converter[a+2] = '7';

converter[a+3] = '7';

a += 4;

}

else if (myString[i] == 'T' || myString[i] == 't') {

converter[a] = '8';

a += 1;

}

else if (myString[i] == 'U' || myString[i] == 'u') {

converter[a] = '8';

converter[a+1] = '8';

a += 2;

}

else if (myString[i] == 'V' || myString[i] == 'v') {

converter[a] = '8';

converter[a+1] = '8';

converter[a+2] = '8';

a += 3;

}

else if (myString[i] == 'W' || myString[i] == 'w') {

converter[a] = '9';

a += 1;

}

else if (myString[i] == 'X' || myString[i] == 'x') {

converter[a] = '9';

converter[a+1] = '9';

a += 2;

}

else if (myString[i] == 'Y' || myString[i] == 'y') {

converter[a] = '9';

converter[a+1] = '9';

converter[a+2] = '9';

a += 3;

}

else if (myString[i] == 'Z' || myString[i] == 'z') {

converter[a] = '9';

converter[a+1] = '9';

converter[a+2] = '9';

converter[a+3] = '9';

a += 4;

}

else {

cout << "You have used wrong character..sorry.." << endl;

exit(0);

}

}




return converter;

}




string Multitap::getString() {

return myString;

}




ostream& operator << (ostream& outs, Multitap & m) {

outs << m.getString() << " = " << m.convertToMultitap();

return outs;

}










-------------------------Main.cpp-------------------------------





#include "Multitap.h"




int main(void)

{

Multitap m;

string str( "World" );




m.setCString( "Hello" );

cout << m << endl;

// should print: "Hello = 4433555555666"




m.clear();

m.setString( str );

cout << m << endl;

// should print: "World = 96667775553"

}

+ -

관련 글 리스트
64458 간단한 프로그램인데 string하는부분 오류좀 잡아주세요 ㅠㅠ K 935 2011/05/29
64459     Re:간단한 프로그램인데 string하는부분 오류좀 잡아주세요 ㅠㅠ 이효신 1105 2011/05/29
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.