Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge #7 (by Plan9)
New Posts  All Forums:Forum Nav:

Programming Challenge #7 (by Plan9) - Page 4

post #31 of 50
Use Interfaces and Abstract classes. Maybe look into the design pattern of the name State. State Design Pattern.
Unto The Void
(16 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7 6800k Gigabyte G1 X99-Phoenix SLI Gigabyte GTX 1080 G1 32GB RipJaw 4 DDR4-3000 
Hard DriveHard DriveHard DriveHard Drive
Samsung 850 500GB Crucial M4 2 x Spinpoint F1 Samsung 850 1TB 
CoolingOSMonitorMonitor
Noctua NH-D15S Windows 10 LG Ultrawide 29" Asus 24" 
KeyboardPowerCaseMouse
Logitech 810 EVGA P2 650 Watt In Win 303 Logitech G502 
  hide details  
Reply
Unto The Void
(16 items)
 
  
CPUMotherboardGraphicsRAM
Intel i7 6800k Gigabyte G1 X99-Phoenix SLI Gigabyte GTX 1080 G1 32GB RipJaw 4 DDR4-3000 
Hard DriveHard DriveHard DriveHard Drive
Samsung 850 500GB Crucial M4 2 x Spinpoint F1 Samsung 850 1TB 
CoolingOSMonitorMonitor
Noctua NH-D15S Windows 10 LG Ultrawide 29" Asus 24" 
KeyboardPowerCaseMouse
Logitech 810 EVGA P2 650 Watt In Win 303 Logitech G502 
  hide details  
Reply
post #32 of 50
Quote:
Originally Posted by Twinnuke View Post

Use Interfaces and Abstract classes. Maybe look into the design pattern of the name State. State Design Pattern.
I'm trying something completely and utterly different this time.
post #33 of 50
Quote:
Originally Posted by 3930K View Post

C# is harder, it's compiled frown.gif
But csc exists. biggrin.gif
Code:
using System;
using System.IO;
using System.Diagnostics;
namespace CalculatorPC7
{
    class Program
    {
        static void Main(string[] args)
        {
            args = new string[0];
            Console.WriteLine("Enter a calculation.");
            string calc = Console.ReadLine();
            calc = calc.Trim();
            StreamWriter writer = new StreamWriter("C:\\Users\\{YourUserName}\\calc.exe", false);
            writer.Write("using System; class Main { void Main() { Console.WriteLine(\"The calculation equals \" + ("+ calc +"));Console.ReadKey(true);}}");
            Process.Start("C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe", "C:\\Users\\{YourUserName}\\calc.txt /out:C:\\Users\\{YourUserName}\\calc.exe");
        }
    }
}
However I don't get what fails her. No exceptions are thrown, csc runs flawlessly, the exe is compiled, but the exe just WON'T work.

See my previous post on how to do it in .NET smile.gif
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #34 of 50
Quote:
Originally Posted by tompsonn View Post

Quote:
Originally Posted by 3930K View Post

C# is harder, it's compiled frown.gif
But csc exists. biggrin.gif
Code:
using System;
using System.IO;
using System.Diagnostics;
namespace CalculatorPC7
{
    class Program
    {
        static void Main(string[] args)
        {
            args = new string[0];
            Console.WriteLine("Enter a calculation.");
            string calc = Console.ReadLine();
            calc = calc.Trim();
            StreamWriter writer = new StreamWriter("C:\\Users\\{YourUserName}\\calc.exe", false);
            writer.Write("using System; class Main { void Main() { Console.WriteLine(\"The calculation equals \" + ("+ calc +"));Console.ReadKey(true);}}");
            Process.Start("C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe", "C:\\Users\\{YourUserName}\\calc.txt /out:C:\\Users\\{YourUserName}\\calc.exe");
        }
    }
}
However I don't get what fails her. No exceptions are thrown, csc runs flawlessly, the exe is compiled, but the exe just WON'T work.

See my previous post on how to do it in .NET smile.gif
I saw the reflection one, I'm just wondering why this won't work.
post #35 of 50
Quote:
Originally Posted by 3930K View Post

I saw the reflection one, I'm just wondering why this won't work.

Because you're writing raw code to an EXE and then trying to compile it from a TXT file that doesn't exist. tongue.gif
You're also forgetting to close and flush that StreamWriter, so even if you were writing to the TXT file, the contents never get written to disk.

Also your CSC isn't running flawlessly - you need to specify the "/out:" option before the source file names.

But even if you DID do that, it still wouldn't work. You've declared the symbol "Main" twice (the class "Main" and the entry point method "Main").
But even if you didn't do that, it still wouldn't work. The class isn't marked as static, and neither is the method "Main".

Try this:
Code:
namespace CalculatorPC7
{
        class Program
        {
                static void Main( string[] args )
                {
                        args = new string[ 0 ];
                        Console.WriteLine( "Enter a calculation." );
                        string calc = Console.ReadLine();
                        calc = calc.Trim();

                        File.WriteAllText( "C:\\Users\\{UserName}\\calc.cs",
                                "using System; static class Program { static void Main() { Console.WriteLine(\"The calculation equals \" + ("+ calc +"));Console.ReadKey(true);}}" );

                        Process.Start( "C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe", "/out:C:\\Users\\{UserName}\\calc.exe C:\\Users\\{UserName}\\calc.cs" );
                }
        }
}

smile.gif
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #36 of 50
Quote:
Originally Posted by tompsonn View Post

Quote:
Originally Posted by 3930K View Post

I saw the reflection one, I'm just wondering why this won't work.

Because you're writing raw code to an EXE and then trying to compile it from a TXT file that doesn't exist. tongue.gif
doh.gif
It should've written to the txt and then compiled using csc.

EDIT: Fixed that small error but it isn't writing at all to the file.
Edited by 3930K - 12/8/12 at 1:08am
post #37 of 50
Quote:
Originally Posted by 3930K View Post

doh.gif
It should've written to the txt and then compiled using csc.
EDIT: Fixed that small error but it isn't writing at all to the file.

See my updated post wink.gif
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #38 of 50
Thanks!
Now it works, but you have to delete calc.exe every time. Let's see, I hope I can figure this out tongue.gif
EDIT:Added a file.delete at the start, now it doesn't find the file even though it's clearly there. UGH.
Edited by 3930K - 12/8/12 at 1:53am
post #39 of 50
Quote:
Originally Posted by 3930K View Post

Thanks!
Now it works, but you have to delete calc.exe every time. Let's see, I hope I can figure this out tongue.gif
EDIT:Added a file.delete at the start, now it doesn't find the file even though it's clearly there. UGH.

CSC doesn't need the file to exist, so I don't know what you mean by "it doesn't find the file."
Unless you mean the CS file and not the EXE (lol).
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #40 of 50
Thread Starter 
Quote:
Originally Posted by tompsonn View Post

CSC doesn't need the file to exist, so I don't know what you mean by "it doesn't find the file."
Unless you mean the CS file and not the EXE (lol).

he's delete file method doesnt find the file
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Programming Challenge #7 (by Plan9)