![]() |
Here you can post your solutions of exams and compare them with others that programm in the same program. :ok:
|
Well
I did in short versions (not that short) in the normal numbers (exercise.cc) I also made somewhat longer version. (probably better according to a book) they are called exercise-long.cc Enjoy edit: C++ as language |
Answers in C#
1. [STAThread] static void Main(string[] args) { Console.WriteLine(Console.ReadLine()); } 2. [STAThread] static void Main(string[] args) { int a; int b; int result; a = Convert.ToInt32(Console.ReadLine()); b = Convert.ToInt32(Console.ReadLine()); result = a + b; Console.WriteLine(result.ToString()); result = a * b; Console.WriteLine(result.ToString()); result = a / b; Console.WriteLine(result.ToString()); result = a - b; Console.WriteLine(result.ToString()); } 3. [STAThread] static void Main(string[] args) { int a; int b; int dummy; a = Convert.ToInt32(Console.ReadLine()); b = Convert,ToInt32(Console.ReadLine()); dummy = a; a = b; b = dummy; Console.WriteLine(a.ToString()); Console.WriteLine(b.ToString()); } 4. [STAThread] static void Main(string[] args) { int a; int b; int result; a = Convert.ToInt32(Console.ReadLine()); b = Convert.ToInt32(Console.ReadLine()); result = a*b; Console.WriteLine(result.ToString()); result = a + a + b + b; Console.WriteLine(result.ToString()); } Easy. |
Quote:
Make a function, which is able to launch any stored procedure in a database, that doesn't return any queries. :evil: The prototype is shown below. public void executeStoredProc(string storedProcedureName, string[] parameterName, string[] parameterValue); The prototype is only a suggestion. You are free to make your own. You may program it in whatever langauage you would like. If it is too easy, just tell me, and I figure out something harder. :Jesus: If I have to post the answer, it will be in C#.net |
Quote:
So could you please solve avion.c from the regional conest 200x. See you in scool. :ok: [/b][/quote] It was an exam from 2002 regional contest in Croatia (now I have to post it :ranting: :ranting: )!!!! Here's the exam: Imagine an aeroplane in which there is only one tiny access batween the lines of seats. Imagine passengers that enter and sit on their places. Every passenger must sit exactly on its seat. Entrance of the aeroplane is on the begining of it. Passengers enter one by one WITHOUT any unnecessary staying and delaying. Passenger walks trough the lines. He is needed ONE SECOND to pass from one line to another (or more if there is a jam in front of him), and FIVE SECONDS to place his things in the space above his seat. In tiny access batween lines can be only ONE PASSENGER. Write a program that will calculate how many time is needed for access to be FREE i.e. to all passengers be sitting on their places. ENTERING PARAMETERS: In first line of the entering file there is a whole number N (number of passengers) 1<=n<=1000. In (i+1) line there is a whole number R (number of line in which passenger number i must sit in) 1<=R<=1000. Passengers are marked with numbers from 1 to N and they enter in aeroplane in that order, and the number of passengers that sit in the same line isn't limited. EXITING PARAMETERS: In first and only line of exiting file, you must write a time (in seconds) that is needed for all passengers to sit down. TEST EXAMPLES: aero.in 1 3 aero.out 7 aero.in 2 3 3 aero.out 12 aero.in 4 4 4 1 5 aero.out 19 If you have any questions about the exam, just ask. I translated it fro Croatian, so it can have some mistakes. |
Quote:
Make a function, which is able to launch any stored procedure in a database, that doesn't return any queries. :evil: The prototype is shown below. public void executeStoredProc(string storedProcedureName, string[] parameterName, string[] parameterValue); The prototype is only a suggestion. You are free to make your own. You may program it in whatever langauage you would like. If it is too easy, just tell me, and I figure out something harder. :Jesus: If I have to post the answer, it will be in C#.net [/b][/quote] //First include your header with wanted stored proc #include "yourheader.h" //This is your function void executeproc(void *procname(),char *parametername,char *parametervalue,int sizeofparameter) { void value,parameter; if(sizeofparameter==sizeof(int)) { sscanf("%d",&(int)parameter); (int)value=parameter; } else if(sizeofparameter==sizeof(float)) { sscanf("%f",&(float)parameter); (float)value=parameter; } . . . //And like this you check type and switch the void in needed type. procname(value); } I did'n test it. So expect some errors. I know it is not a very good procedure becouse i operates only with one parameter of that proc. you have stored. And I don't know how to use function with unknown number of parameters (function(blah,blah,...)). PS: I see you program in c# ,could you explain a little, difrences from ordinary c/c++. I do c. :kosta: |
Here are the solutions for first 4 exams:
First.pas Second.pas Third.pas Fourth.pas And here they are all in one 'big' txt file: Solution.txt |
Quote:
#include "yourheader.h" //This is your function void executeproc(void *procname(),char *parametername,char *parametervalue,int sizeofparameter) { void value,parameter; if(sizeofparameter==sizeof(int)) { sscanf("%d",&(int)parameter); (int)value=parameter; } else if(sizeofparameter==sizeof(float)) { sscanf("%f",&(float)parameter); (float)value=parameter; } . . . //And like this you check type and switch the void in needed type. procname(value); } I did'n test it. So expect some errors. I know it is not a very good procedure becouse i operates only with one parameter of that proc. you have stored. And I don't know how to use function with unknown number of parameters (function(blah,blah,...)). PS: I see you program in c# ,could you explain a little, difrences from ordinary c/c++. I do c. :kosta:[/b][/quote] To give the function an unknown number of parameters, you need to work with arrays. Below I have written a way to solve the problem in C#. If you open a new thread dedicated to talk about the difference between C/C++ and C#, I will gladly post. public void executeStoredProc(string storedProcedureName, string[] parameterName, string[] parameterValue) { OleDbConnection objConn = new OleDbConnection("Connectionstring"); //The connectionstring depends on, which database you are using. OleDbCommand objCommand = objConn.CreateCommand(); objCommand.CommandType = CommandType.StoredProcedure; objCommand.CommandText = storedProcedureName; for (int index = 0; index < parameterName.Length; index++) { objCommand.Parameters.Add(parameterName[index], parameterValue[index]; } try { objConn.Open(); objCommand.ExecuteNonQuery(); } catch { throw new Exception("Error while executing procedure"); } finally { objConn.Close(); } } This should work. ;) |
I guess I still remember Basic :blink:
1) PRINT "Type in somewhat and press Return" INPUT a$ PRINT a$ 2) PRINT "Type in the first number and press Return" INPUT a PRINT "Type in the second number and press Return" INPUT b PRINT a+b PRINT a*b PRINT a/b PRINT a-b 3) PRINT "Type in the first number and press Return" INPUT a PRINT "Type in the second number and press Return" INPUT b PRINT b PRINT a 4) PRINT "Type in length of side a" INPUT a PRINT "Type in length of side b" INPUT b PRINT "Area is" , a*b PRINT "Circumfence is" , a+a+b+b Was it this that you were thinging about? I do not know if it runs, last time i programmed it is 15 years ago :D |
Quote:
If you open a new thread dedicated to talk about the difference between C/C++ and C#, I will gladly post. public void executeStoredProc(string storedProcedureName, string[] parameterName, string[] parameterValue) { OleDbConnection objConn = new OleDbConnection("Connectionstring"); //The connectionstring depends on, which database you are using. OleDbCommand objCommand = objConn.CreateCommand(); objCommand.CommandType = CommandType.StoredProcedure; objCommand.CommandText = storedProcedureName; for (int index = 0; index < parameterName.Length; index++) { objCommand.Parameters.Add(parameterName[index], parameterValue[index]; } try { objConn.Open(); objCommand.ExecuteNonQuery(); } catch { throw new Exception("Error while executing procedure"); } finally { objConn.Close(); } } This should work. ;) [/b][/quote] Ok this is great but I don't understand a thing of object-oriented programing. Supose I need more knowledge. I won't open a tread becouse I don't know c++, and as I know a little c++ and c# are more diferent then ordinary c. But thanks anyway. :ok: |
The current time is 01:42 AM (GMT) |
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.