Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
<pre lang="C++">#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
#include <stdio.h>
#include <stdlib.h>

using namespace std;


int main()
{

    int accumulator =0;
    int n;
    int i=0;
    int x=00;

    string c;
    const char *b;
    int memory[100];
    ifstream ifs;
    int counter=0;
    ifs.open("program.txt",ios::in);
    if(ifs){
        for(int i=0 ; i<100 && !ifs.eof();i++){
            getline(ifs,c);
            b=c.c-str();
            memory[i]=atoi(b);
            counter++;
        }
        ifs.close();
    }else{
        cout<<"Error";
    }

    for(int i=0 ;i<counter;i++){
        cout<<x<<" ?"<<memory[i]<<endl;
    }




    cout<<"*** Welcome to Simpletron! ***\n";
    cout<<"*** Please enter your program one instruction ***\n";
    cout<<"*** (or data word) at a time. I will type the ***\n";
    cout<<"*** location number and a question mark (?).  ***\n";
    cout<<"*** You then type the word for that location. ***\n";
    cout<<"*** Type the sentinel -99999 to stop entering ***\n";
    cout<<"*** your program. ***\n";



    //2 raghame avale ram
    int opCode ;
    //2raghame dovome ram
    int operand ;


    int instructionRegister;
    for(int i=0;i<counter;i++){
        instructionRegister=memory[i];
        opCode =instructionRegister/100;
        operand =instructionRegister%100;
        switch (opCode ){
        case 10:
            //Read a word from the keyboard into a specific location in memory.
            cout<<"plz enter a number:\n";
            cin>>memory[operand];
            break;
        case 11:
            //Write a word from a specific location in memory to the screen.
            cout<<memory[operand]<<'\n';
            break;
        case 20:
            //Load a word from a specific location in memory into the accumulator.
            accumulator=memory[operand];
            break;
        case 21:
            //Store a word from the accumulator into a specific location in memory.
            memory[operand]=accumulator;
            break;
        case 30:
            //Add a word from a specific location in memory to the word in the accumulator(Resgister) -leave result in accumulator.
            accumulator+=memory[operand];
            break;
        case 31:
            //Subtract a word from a specific location in memory from the word in the accumulator(Resgister) -leave result in accumulator.
            accumulator-=memory[operand];
            break;
        case 32:
            //Divide a word from a specific location in memory into the word in the accumulator(Resgister) -leave result in accumulator.
            accumulator=memory[operand]/accumulator;
            break;
        case 33:
            //Multiply a word from a specific location in memory by the word in the accumulator(Resgister) -leave result in accumulator.
            accumulator=memory[operand]*accumulator;
            break;
        //case 40:
           // i = memory[operand] - 1;
            //break;
       // case 41:
            //Branch to a specific location in memory if the accumulator is negative.
          //  i = (accumulator < 0 ? (memory[operand] - 1) : i);
            //break;
       // case 42:
            //Branch to a specific location in memory if the accumulator is zero.
            //i = (accumulator == 0 ? (memory[operand] - 1) : i);
           // break;
        //case 43:
           //Halt the program has completed its task.
          // i = 101;
          // break;
        /*default:
        Cout<<"Error: Wrong operation code. Program halt";
          break;*/
        }
    }


    getch();
    return 0;
}



txt
Error   1   error C2039: 'c' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'    c:\users\sama\documents\visual studio 2010\projects\11\11\11.cpp    32
Error   2   error C3861: 'str': identifier not found    c:\users\sama\documents\visual studio 2010\projects\11\11\11.cpp    32
    3   IntelliSense: class "std::basic_string<char, std::char_traits<char>, std::allocator<char>>" has no member "c"   c:\users\sama\documents\visual studio 2010\projects\11\11\11.cpp    32
    4   IntelliSense: identifier "str" is undefined c:\users\sama\documents\visual studio 2010\projects\11\11\11.cpp    32

:confused:
Posted
Updated 12-Feb-11 2:18am
v5
Comments
Emilio Garavaglia 12-Feb-11 3:06am    
format adjusted

Perhaps, if you look at line number 32 in your source file
Error   1   error C2039: 'c' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'    c:\users\sama\documents\visual studio 2010\projects\11\11\11.cpp    32
The number at the end is the line number.

In VS, you can go to a specific line number by pressing CTRL+G.

Since you don't appear to have shown us the line with the error, it is going to be up to you, but I suspect a spelling error!
 
Share this answer
 
Comments
Andrew Brock 12-Feb-11 6:11am    
You are correct. Now that full code is provided we can see exactly where. 5+.
Sergey Alexandrovich Kryukov 13-Feb-11 0:17am    
Just the advice to get line # gets 5.
--SA
OriginalGriff is absolutely correct:
if(ifs){
    for(int i=0 ; i<100 && !ifs.eof();i++){
        getline(ifs,c);
        b=c.c_str(); //you had "c-str"
        memory[i]=atoi(b);
        counter++;
    }
    ifs.close();
}
 
Share this answer
 
Comments
OriginalGriff 12-Feb-11 6:44am    
That's the one: gets my 5!
Sergey Alexandrovich Kryukov 13-Feb-11 0:16am    
You spotted! My 5.
--SA
The code you posted is not related to your errors. I would guess you somewhere have written
C++
string s;
s.c;
// or
s.c();

Did you intend to write s.c_str() ?

Check the file c:\users\sama\documents\visual studio 2010\projects\11\11\11.cpp on line 32
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900