Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 20-02-2005, 04:54 PM   #1
Unknown Hero
Home Sweet Abandonia

 
Join Date: Aug 2004
Location: Split, Croatia
Posts: 1,028
Default

Here you can post your solutions of exams and compare them with others that programm in the same program. k:
Unknown Hero is offline                         Send a private message to Unknown Hero
Reply With Quote
Old 21-02-2005, 06:53 PM   #2
Data
retired
 
Data's Avatar


 
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
Default

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
__________________
Flowing with the stream of life
Data is offline                         Send a private message to Data
Reply With Quote
Old 22-02-2005, 09:22 AM   #3
aaberg
Game Wizzard

 
Join Date: Aug 2004
Location: Aasane, Norway
Posts: 238
Default

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.
aaberg is offline                         Send a private message to aaberg
Reply With Quote
Old 23-02-2005, 11:55 AM   #4
aaberg
Game Wizzard

 
Join Date: Aug 2004
Location: Aasane, Norway
Posts: 238
Default

Quote:
Originally posted by Unknown Hero@Feb 23 2005, 12:05 AM
You can chalenge me! I'm in! k:*
Ok. Here is my challenge.

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
aaberg is offline                         Send a private message to aaberg
Reply With Quote
Old 24-02-2005, 08:52 PM   #5
Unknown Hero
Home Sweet Abandonia

 
Join Date: Aug 2004
Location: Split, Croatia
Posts: 1,028
Default

Quote:
Originally posted by NrmMyth+Feb 24 2005, 09:23 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>QUOTE (NrmMyth @ Feb 24 2005, 09:23 PM)</td></tr><tr><td id='QUOTE'>
Quote:
Originally posted by Unknown Hero@Feb 22 2005, 03:36 PM
<!--QuoteBegin-aaberg
Quote:
@Feb 22 2005, 11:22 AM
Answers in C#

Easy.

EASY?????

Muahahahahahahahahahahah!!! :twisted:

You wont say that after a few months when I arrive at difficult ones! LOL
I see that the Unknown Hero is a good programer.
So could you please solve avion.c from the regional conest 200x.

See you in scool. k: [/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.
Unknown Hero is offline                         Send a private message to Unknown Hero
Reply With Quote
Old 25-02-2005, 04:08 PM   #6
NrmMyth
Hero Gamer

 
Join Date: Jan 2005
Location: ,
Posts: 454
Red face

Quote:
Originally posted by aaberg+Feb 23 2005, 12:55 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>QUOTE (aaberg @ Feb 23 2005, 12:55 PM)</td></tr><tr><td id='QUOTE'> <!--QuoteBegin-Unknown Hero@Feb 23 2005, 12:05 AM
You can chalenge me! I'm in! k:*
Ok. Here is my challenge.

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.
__________________
Never mess with me when I have a cougar, Never!
NrmMyth is offline                         Send a private message to NrmMyth
Reply With Quote
Old 27-02-2005, 04:37 PM   #7
Unknown Hero
Home Sweet Abandonia

 
Join Date: Aug 2004
Location: Split, Croatia
Posts: 1,028
Default

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
Unknown Hero is offline                         Send a private message to Unknown Hero
Reply With Quote
Old 01-03-2005, 08:44 AM   #8
aaberg
Game Wizzard

 
Join Date: Aug 2004
Location: Aasane, Norway
Posts: 238
Default

Quote:
Originally posted by NrmMyth+Feb 25 2005, 05:08 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>QUOTE (NrmMyth @ Feb 25 2005, 05:08 PM)</td></tr><tr><td id='QUOTE'>
Quote:
Originally posted by aaberg@Feb 23 2005, 12:55 PM
<!--QuoteBegin-Unknown Hero
Quote:
@Feb 23 2005, 12:05 AM
You can chalenge me! I'm in! k:*

Ok. Here is my challenge.

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
//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. [/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.
aaberg is offline                         Send a private message to aaberg
Reply With Quote
Old 01-03-2005, 11:38 AM   #9
piepsi
Newbie

 
Join Date: Feb 2005
Location: ,
Posts: 16
Default

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
piepsi is offline                         Send a private message to piepsi
Reply With Quote
Old 01-03-2005, 08:43 PM   #10
NrmMyth
Hero Gamer

 
Join Date: Jan 2005
Location: ,
Posts: 454
Default

Quote:
Originally posted by aaberg+Mar 1 2005, 09:44 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>QUOTE (aaberg @ Mar 1 2005, 09:44 AM)</td></tr><tr><td id='QUOTE'>
Quote:
Originally posted by NrmMyth@Feb 25 2005, 05:08 PM
Quote:
Originally posted by aaberg@Feb 23 2005, 12:55 PM
<!--QuoteBegin-Unknown Hero
Quote:
Quote:
@Feb 23 2005, 12:05 AM
You can chalenge me! I'm in! k:*

Ok. Here is my challenge.

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

//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.
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.
[/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. k:
__________________
Never mess with me when I have a cougar, Never!
NrmMyth is offline                         Send a private message to NrmMyth
Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Discussion Of Exams Kon-Tiki Programming 8 30-03-2007 07:27 PM
How Often Do You Cheat On Exams / Tests nace Blah, blah, blah... 40 16-10-2006 07:57 PM
Solution To Exams Kon-Tiki Programming 0 08-08-2005 05:37 PM
Exams Unknown Hero Programming 0 12-04-2005 08:40 PM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 02:44 PM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.