Here i am going to show you some basic C++ Programming... If you have any questions just ask. Code: #include <cstdlib> // This must be used if you are going to be a MS-DOS Application. #include <iostream> // This must be included in the header file if you are going to use "Cout" and "Cin" using namespace std; int MittSvar(int tall1, int tall2, char stykke); // Here we make an Function so is going to calculate for us. void Manual(); // This is user Manual so is going to tell us how to use the Program. int main(int argc, char *argv[]) // int main() is the program file. { // starting program. (Starting Block) // we are defind the inputs so you are going to use so the program know how to handle them. int tall1; // int = Integer = This will say that only input so will be accepted is integer. int tall2; // int = Integer = This will say that only input so will be accepted is integer. char stykke; // char = Character = This will say that only input so will be accepted is letters. ect + // The Function void does't need any return Value. Manual(); // Here will the User Manaul be Displayed. system("PAUSE >nul"); // Press an Key to Continue (Hidden). system("cls"); // Clear Screen. cout<<"Type: "<<endl; // Prints "Type" on the screen. cin>>tall1>>stykke>>tall2; // Exampel 13 + 13. Remember to press Enter between them. system("cls"); // Clear Screen. int svar = MittSvar(tall1, tall2, stykke); // Svar is the return Value of the Function. cout<<tall1<<stykke<<tall2<<"="<<svar; // Prints: tall1+tall2=svar (Exampel 20+20=40) system("PAUSE >nul"); // Press an Key to Continue (Hidden) return 0; // Exit Program. } // End Program (End Block) int MittSvar( // Start of the Calc Function. int tall1, int tall2, char stykke) { // (Starting Block) int svar; // Answer of the Calc Value is going to be saved in. // "if" command is used to true or false. IF (stykke == '+') means if the "char stykke" is + it. // int Svar will give answer in +. Exampel (13+13=26) 13 = tall1 , + = stykke , 13 = tall2; if (stykke == '+') svar = tall1 + tall2; // Here are we showing the Function how it should act when you put in the Values. if (stykke == '-') svar = tall1 - tall2; // Here are we showing the Function how it should act when you put in the Values. if (stykke == '*') svar = tall1 * tall2; // Here are we showing the Function how it should act when you put in the Values. if (stykke == '/') svar = tall1 / tall2; // Here are we showing the Function how it should act when you put in the Values. } // (End Block) void Manual() //Starting Void Function. { // (Starting Block) cout<<"This is a calc."; // Here is what so should be displayed in the Manual Function. cout<<"Writing in what you want to calculate."<<endl; // Here is what so should be displayed in the Manual Function. cout<<"Example 20 + 20 = 40. Allowed characters are "; // Here is what so should be displayed in the Manual Function. cout<<"'+' . '-' . '/' . '*'"; // Here is what so should be displayed in the Manual Function. } // (End Block)
Good comments! But you should explain in detail how you would put this together as opposed to just showing us. It would help the newbs a lot.
Not bad but, here you define the function as an int rather then a void yet it returns nothing. Why? Code: int MittSvar() Code: if (stykke == '+') svar = tall1 + tall2; // Here are we showing the Function how it should act when you put in the Values. if (stykke == '-') svar = tall1 - tall2; // Here are we showing the Function how it should act when you put in the Values. if (stykke == '*') svar = tall1 * tall2; // Here are we showing the Function how it should act when you put in the Values. if (stykke == '/') svar = tall1 / tall2; // Here are we showing the Function how it should act when you put in the Values. Badly made since a switch/case is superior here. Code: system("PAUSE >nul"); Never use system calls for this, since you use C++ do cin.getline(). Otherwise great stuff.
guyz... please help me... send me a software of c++ and examples of this programs to my e-mail address: glrex06@yahoo.com.ph. Thank you in advance...
C++ is an object-oriented version of C that has been widely used to develop enterprise and commercial applications. C++ became popular because it combined traditional C programming with object-oriented programming features. Smalltalk and other OOP languages did not provide the familiar structures of conventional languages such as C and Pascal. Microsoft's Visual C++ is the most widely used C++ language. An example: Code: #include <iostream> class Bird // the "generic" base class { public: virtual void OutputName() {std::cout << "a bird";} virtual ~Bird() {} }; class Swan : public Bird // Swan derives from Bird { public: void OutputName() {std::cout << "a swan";} // overrides virtual function }; int main() { Swan mySwan; // Creates a swan. Bird* myBird = &mySwan; // Declares a pointer to a generic Bird, // and sets it pointing to a newly created Swan. myBird->OutputName(); // This will output "a swan", not "a bird". return 0; }
The biggest misconception of the century I guess. C++ is totally different from C semantically but supports the syntax of C
Its very good thing to explain how to work in a language.its very useful for newly learner languages.good going keep it up.