• 0

Easy way to convert code C# to C++


 Share

Question

Is there any way to convert C# program to C++

 

For e.g. here I have resolved one code problem using C# now I trying to find automated way to convert C# to C++ 

Edited by cbz6109
Added more descriptions
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By +Biscuits Brown
      I have a shared drive mapped to my local as drive Z. Using Windows Explorer, I can create directories in that folder all day long. The moment I try to add a directory from anywhere else, I get an error (a device attached to the system is not functioning). I'd ideally like to create the new directory from C# - which throws that same exception. I've tried xcopy and robocopy and both of those also fail with the same error.
       
      So, does anyone know why creating a folder would work 100% of the time in explorer and 0% from anywhere else (including the most needed C# code)?
       
      I've tried both of these to no avail
      var di = new DirectoryInfo("z:\"); di.CreateSubDirectory("Test"); var di = new DirectoryInfo("\\servername\sharename\attachments\"); di.CreateSubDirectory("Test");  
      I've also tried (where test is the folder I'd like created)
      xcopy file.txt z:\test\file.txt /T  robocopy c:\ z:\test\ file.txt /COPY:DT  
      I've also done this with no happiness... Same error
      c:\> z: z:\> md test  
       
      If I navigate to either the Z drive or the share directly in Windows Explorer, I can right click and add a folder (and rename it).  I'm stumped.   I keep thinking its a permissions issue of some kind but then rationalize that Explorer and a command prompt are both running as my user (non-elevated) so how can permissions come into play.. 
       
      Any one have any ideas?
       
       
          
    • By DevTech
      I keep a list of UWP libs on my GitHUb here:
       
      https://github.com/10UWP/The-UWP-Tools-List
       
      Any suggestions for additions are appreciated.   Any disscusion on UWP devlepment is welcome
    • By pinacallada1
      I am making a simple 5- a side text based football game for uni, problem is i suck at programming and have really messed it up so now im stuck as to what to do. The task description is only really to think of a simple 5 a-side game with goalkeeper (who can save), defenders (who can tackle) and attackers (who can shoot).  All players have a Name, a position and can pass, dribble and run. This includes a hasball feature which will check if a particular player has the ball. So far i have a basic code i made to work off for my classes, i can think of what i need to do exactly but i just don't know how to express it in code.
       
      So far i only need to build off classes for the interfaces below but i cant seem to get any arrays working with it, i don't know how to implement the shoot, tackle run actions, its my first time programming this semester and im still getting used to everything i don't want to fall behind or possibly fail because of one module. What i have to work off is follows:
       
      interface IFootballPlayer
          {
              string Name { get; set; }
              bool HasBall { get; set; }
              int XPos { get; set; }
              int YPos { get; set; }
       
              void Pass(FootballPlayer receiver);
              void Dribble(int x, int y);
              void Run(int x, int y);
              string ToString();
          }
       
          interface IGoalKeeper
          {
              int SaveSkill { get; set; }
              void Save(Attacker attacker);
          }
       
          interface IDefender
          {
              int TackleSkill { get; set; }
              void Tackle(Attacker attacker);
          }
       
          interface IAttacker
          {
              int ShootSkill { get; set; }
              void Shoot(GoalKeeper goalKeeper);
          }
       
      If i can get this sorted ill be able to scrape a pass hopefully
      I would be grateful for any advice, C# still looks like a alien language to me
    • By Ch33f
      Here is what the form looks like and its respective toolbox item name
       
      Form and it's names
       
      Here's the code for the Form and the class
       
      public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void addFlapjacks_Click(object sender, EventArgs e) { Flapjack food; if (crispy.Checked == true) food = Flapjack.Crispy; else if (soggy.Checked == true) food = Flapjack.Soggy; else if (browned.Checked == true) food = Flapjack.Browned; else food = Flapjack.Bannana; Lumberjack currentLumberjack = breakfastLine.Peek(); currentLumberjack.TakeFlapjacks(food, (int)howMany.Value); RedrawList(); } private Queue<Lumberjack> breakfastLine = new Queue<Lumberjack>(); private void addLumberjack_Click(object sender, EventArgs e) { breakfastLine.Enqueue(new Lumberjack(name.Text)); name.Text = ""; RedrawList(); } private void RedrawList() { int number = 1; line.Items.Clear(); foreach (Lumberjack lumberjack in breakfastLine) { line.Items.Add(number + ". " + lumberjack.Name); number++; } if (breakfastLine.Count == 0) { groupBox1.Enabled = true; Lumberjack currentLumberjack = breakfastLine.Peek(); nextInLine.Text = currentLumberjack.Name + " has " + currentLumberjack.FlapjackCount + " flapjacks."; } } private void nextLumberjack_Click(object sender, EventArgs e) { Lumberjack nextLumberjack = breakfastLine.Dequeue(); nextLumberjack.EatFlapjacks(); nextInLine.Text = ""; RedrawList(); } } CLASS:
       
      enum Flapjack { Crispy, Soggy, Browned, Bannana } class Lumberjack { private string name; public string Name { get { return name; } } private Stack<Flapjack> meal; public Lumberjack(string name) { this.name = name; meal = new Stack<Flapjack>(); } public int FlapjackCount { get { return meal.Count; } } public void TakeFlapjacks(Flapjack food, int howMany) { for (int i = 0; i < howMany; i++) { meal.Push(food); } } public void EatFlapjacks() { Console.WriteLine(name + "'s eating flapjacks"); while(meal.Count > 0) { Console.WriteLine(name + " ate a " + meal.Pop().ToString().ToLower() + " flapjack"); } } } The problem here i'm getting is in Form1 under RedrawList() ---> nextInLine TextBox should display what ever nextInLine.Text line is equal to but nothing is being displayed in the textbox during execution, up on button click of Add flapjacks it will call RedrawList () and a mesage should be displayed in the textbox like if name = ed and howMany = 3 text displaayed should be "Ed has 3 flapjacks" not no display upon button click.
      I have set the property of the textbox to Read only, 
      Any Idea why there is no text in textbox ?
    • By Ch33f
      The Form has 4 classes Card, Deck , Player and Game, game being the class that runs everything
      The form has 3 TextBox named textName, textBooks and textProgress , ListBox named listHand, 2 buttons named buttonStart and buttonAsk
       
      Card
      class Card { public Values Value { get; set; } public Suits Suit {get; set;} public Card (Suits suit, Values value) { this.Suit = suit; this.Value = value; } public string Name { get { return Value.ToString() + " of " + Suit.ToString(); } } public override string ToString() { return Name; } public static string Plural(Values value) { if (value == Values.Six) return "Sixes"; else return value.ToString() + "s"; } } enum Suits { Spades, Clubs, Hearts, Diamonds, } enum Values { Ace = 1, Two = 2, Three = 3, Four = 4, Five = 5, Six = 6, Seven = 7, Eight = 8, Nine = 9, Ten = 10, Jack = 11, Queen = 12, King = 13, }  
      Deck
      class Deck { private List<Card> cards; private Random random = new Random(); public Deck() { cards = new List<Card>(); for (int suit = 0; suit <= 3; suit++) for (int value = 1; value <= 13; value++) cards.Add(new Card((Suits)suit, (Values)value)); } public Deck(IEnumerable<Card> initialCards) { cards = new List<Card>(initialCards); } public int Count { get { return cards.Count; } } public void Add(Card cardToAdd) { cards.Add(cardToAdd); } public Card Deal(int index) { Card CardToDeal = cards[index]; cards.RemoveAt(index); return CardToDeal; } public void Shuffle() { List<Card> NewCards = new List<Card>(); while(cards.Count > 0) { int CardToMove = random.Next(cards.Count); NewCards.Add(cards[CardToMove]); cards.RemoveAt(CardToMove); } cards = NewCards; } public IEnumerable<string> GetCardNames() { string[] CardNames = new string[cards.Count]; for (int i = 0; i < cards.Count; i++) CardNames[i] = cards[i].Name; return CardNames; } public void Sort() { cards.Sort(new CardComparer_bySuit()); } public Card Peek(int cardNumber) { return cards[cardNumber]; } public Card Deal() { return Deal(0); } public bool ContainsValue(Values value) { foreach (Card card in cards) if (card.Value == value) return true; return false; } public Deck PullOutValues(Values value) { Deck deckToReturn = new Deck(new Card[] { }); for (int i = cards.Count - 1; i >= 0; i--) if (cards[i].Value == value) deckToReturn.Add(Deal(i)); return deckToReturn; } public bool HasBook(Values value) { int NumberOfCards = 0; foreach (Card card in cards) if (card.Value == value) NumberOfCards++; if (NumberOfCards == 4) return true; else return false; } public void SortByValue() { cards.Sort(new CardComparer_byValue()); } } class CardComparer_bySuit : IComparer<Card> { public int Compare(Card x, Card y) { if (x.Suit > y.Suit) return 1; if (x.Suit < y.Suit) return -1; if (x.Value > y.Value) return 1; if (x.Value < y.Value) return -1; return 0; } } class CardComparer_byValue : IComparer<Card> { public int Compare(Card x, Card y) { if (x.Value < y.Value) return -1; if (x.Value > y.Value) return 1; if (x.Suit < y.Suit) return -1; if (x.Suit > y.Suit) return 1; return 0; } } Player
      class Player { private string name; public string Name { get { return name; } } private Random random; private Deck cards; private TextBox textBoxOnForm; public Player(String name, Random random, TextBox textBoxOnForm) { this.name = name; this.random = random; this.textBoxOnForm = textBoxOnForm; this.cards =new Deck(new Card[]{ }); textBoxOnForm.Text += name + "has joined the game" + Environment.NewLine; } public IEnumerable<Values> PullOutBooks() { List<Values> books = new List<Values>(); for (int i = 1; i<= 13; i++) { Values value = (Values)i; int howMany = 0; for (int card = 0; card < cards.Count; card++) if (cards.Peek(card).Value == value) howMany++; if(howMany == 4) { books.Add(value); for (int card = cards.Count - 1; card >= 0; card--) cards.Deal(card); } } return books; } public Values GetRandomValue() { Card randomCard = cards.Peek(random.Next(cards.Count)); return randomCard.Value; } public Deck DoYouHaveAny(Values value) { Deck cardsIHave = cards.PullOutValues(value); textBoxOnForm.Text += Name + "has" + cardsIHave.Count + "" + Card.Plural(value) + Environment.NewLine; return cardsIHave; } public void AskForACard(List<Player> players, int myIndex,Deck stock) { Values randomValue = GetRandomValue(); AskForACard(players, myIndex, stock, randomValue); } public void AskForACard(List<Player>players, int myIndex, Deck stock, Values value) { textBoxOnForm.Text += Name + "asks if anyone has a " + value + Environment.NewLine; int totalCardsGiven = 0; for(int i = 0; i<players.Count; i++) { if(i != myIndex) { Player player = players[i]; Deck CardsGiven = player.DoYouHaveAny(value); totalCardsGiven += CardsGiven.Count; while (CardsGiven.Count > 0) cards.Add(CardsGiven.Deal()); } } if(totalCardsGiven == 0) { textBoxOnForm.Text += Name + "must draw from teh stock." + Environment.NewLine; cards.Add(stock.Deal()); } } public int CardCount { get { return cards.Count; } } public void TakeCard(Card card) { cards.Add(card); } public IEnumerable<string> GetCardNames() { return cards.GetCardNames(); } public Card Peek(int cardNumber) { return cards.Peek(cardNumber); } public void SortHand() { cards.SortByValue(); } } Game
      class Game { private List<Player> players; private Dictionary<Values, Player> books; private Deck stock; private TextBox textBoxOnForm; public Game(string playerName, IEnumerable<string> opponentNames, TextBox textBoxOnForm) { Random random = new Random(); this.textBoxOnForm = textBoxOnForm; players = new List<Player>(); players.Add(new Player(playerName, random, textBoxOnForm)); foreach (string player in opponentNames) players.Add(new Player(player, random, textBoxOnForm)); books = new Dictionary<Values, Player>(); stock = new Deck(); Deal(); players[0].SortHand(); } private void Deal() { stock.Shuffle(); for (int i = 0; i < 5; i++) foreach (Player player in players) player.TakeCard(stock.Deal()); foreach (Player player in players) PullOutBooks(player); } public bool PlayOneRound(int selectedPlayerCard) { Values cardToAskFor = players[0].Peek(selectedPlayerCard).Value; for(int i = 0; i < players.Count; i++) { if (i == 0) players[0].AskForACard(players, 0, stock, cardToAskFor); else players[i].AskForACard(players, i, stock); if (PullOutBooks(players[i])) { textBoxOnForm.Text += players[i].Name + "drew a new hand" + Environment.NewLine; int card = 1; while(card <=5 && stock.Count > 0) { players[i].TakeCard(stock.Deal()); card++; } } players[0].SortHand(); if(stock.Count == 0) { textBoxOnForm.Text = "The stock is out of cards.Game over!" + Environment.NewLine; return true; } } return false; } public bool PullOutBooks(Player player) { IEnumerable<Values> booksPulled = player.PullOutBooks(); foreach (Values value in booksPulled) books.Add(value, player); if (player.CardCount == 0) return true; return false; } public string DescribeBooks() { string whoHasWhichBooks = ""; foreach (Values value in books.Keys) whoHasWhichBooks += books[value].Name + "has a book of" + Card.Plural(value) + Environment.NewLine; return whoHasWhichBooks; } public string GetWinnerName() { Dictionary<string, int> winners = new Dictionary<string, int>(); foreach (Values value in books.Keys) { string name = books[value].Name; if (winners.ContainsKey(name)) winners[name]++; else winners.Add(name, 1); } int mostBooks = 0; foreach (string name in winners.Keys) if (winners[name] > mostBooks) mostBooks = winners[name]; bool tie = false; string winnerList =""; foreach(string name in winners.Keys) if(winners[name]== mostBooks) { if(!string.IsNullOrEmpty(winnerList)) { winnerList += "and"; tie = true; } winnerList += name; } winnerList += "with" + mostBooks + "books"; if (tie) return "A tie between" + winnerList; else return winnerList; } public IEnumerable<string> GetPlayerCardNames() { return players[0].GetCardNames(); } public string DescribePlayerHands() { string description = ""; for (int i= 0; i < players.Count; i++) { description += players[i].Name + "hase" + players[i].CardCount; if (players[i].CardCount == 1) description += "card." + Environment.NewLine; else description += "cards." + Environment.NewLine; } description += "The stock has" + stock.Count + "cards left."; return description; } } The Program
      public partial class Form1 : Form { public Form1() { InitializeComponent(); } private Game game; private void buttonStart_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(textName.Text)) { MessageBox.Show("Please enter your name", " Can't start the game yet"); return; } game = new Game(textName.Text, new List<string> { "Joe", "Bob" }, textProgress); buttonStart.Enabled = false; textName.Enabled = false; buttonAsk.Enabled = true; UpdateForm(); } private void UpdateForm() { listHand.Items.Clear(); foreach (String cardName in game.GetPlayerCardNames()) listHand.Items.Add(cardName); textBooks.Text = game.DescribeBooks(); textProgress.Text += game.DescribePlayerHands(); textProgress.SelectionStart = textProgress.Text.Length; textProgress.ScrollToCaret(); } private void buttonAsk_Click(object sender, EventArgs e) { textProgress.Text = ""; if(listHand.SelectedIndex < 0) { MessageBox.Show("Please select a card"); return; } if (game.PlayOneRound(listHand.SelectedIndex)) { textProgress.Text += "The winner is..." + game.GetWinnerName(); textBooks.Text = game.DescribeBooks(); buttonAsk.Enabled = false; } else UpdateForm(); } } The Game runs fine, but my question here is , I can't understand how the method GetWinnerName( ) in the class Game is working
       
      In this loop
       foreach (Values value in books.Keys)
                  {
                      string name = books[value].Name; 
                      if (winners.ContainsKey(name)) //What is ContainsKey ?
                          winners[name]++; // What is happening here ?
                      else
                          winners.Add(name, 1); // What is happening here ?
                  }