Note that there are some explanatory texts on larger screens.

plurals
  1. POTransitioning from C# to C++, good references?
    primarykey
    data
    text
    <p>I've just completed my second OOP class, and both my first and second classes were taught in C#, but for the rest of my programming classes, we will be working in C++. Specifically, we will be using the visual C++ compliler. The problem is, we are required to learn the basics of C++ ourself, with no transition from our professor. So, I was wondering if any of you know of some good resources I could go to to learn about C++, coming from a c# background?</p> <p>I ask this because I've noticed many diffferences between C# and C++, such as declaring your <code>main</code> method int, and returning a 0, and that your main method is not always contained in a class. Also, I've noticed that all of your classes have to be written before your main method, I heard that this is because VC++ complies from the top down?</p> <p>Anyway, do you know of some good references?</p> <p>Thanks! (Also, is there somewhere out there where I can compare simple programs I've written in C#, to see what they would look like in C++, such as the one I wrote that is below)?</p> <pre><code>using System; using System.IO; using System.Text; // for stringbuilder class Driver { const int ARRAY_SIZE = 10; static void Main() { PrintStudentHeader(); // displays my student information header Console.WriteLine("FluffShuffle Electronics Payroll Calculator\n"); Console.WriteLine("Please enter the path to the file, either relative to your current location, or the whole file path\n"); int i = 0; Console.Write("Please enter the path to the file: "); string filePath = Console.ReadLine(); StreamReader employeeDataReader = new StreamReader(filePath); Employee[] employeeInfo = new Employee[ARRAY_SIZE]; Employee worker; while ((worker = Employee.ReadFromFile(employeeDataReader)) != null) { employeeInfo[i] = worker; i++; } for (int j = 0; j &lt; i; j++) { employeeInfo[j].Print(j); } Console.ReadLine(); }//End Main() class Employee { const int TIME_AND_A_HALF_MARKER = 40; const double FEDERAL_INCOME_TAX_PERCENTAGE = .20; const double STATE_INCOME_TAX_PERCENTAGE = .075; const double TIME_AND_A_HALF_PREMIUM = 0.5; private int employeeNumber; private string employeeName; private string employeeStreetAddress; private double employeeHourlyWage; private int employeeHoursWorked; private double federalTaxDeduction; private double stateTaxDeduction; private double grossPay; private double netPay; // -------------- Constructors ---------------- public Employee() : this(0, "", "", 0.0, 0) { } public Employee(int a, string b, string c, double d, int e) { employeeNumber = a; employeeName = b; employeeStreetAddress = c; employeeHourlyWage = d; employeeHoursWorked = e; grossPay = employeeHourlyWage * employeeHoursWorked; if (employeeHoursWorked &gt; TIME_AND_A_HALF_MARKER) grossPay += (((employeeHoursWorked - TIME_AND_A_HALF_MARKER) * employeeHourlyWage) * TIME_AND_A_HALF_PREMIUM); stateTaxDeduction = grossPay * STATE_INCOME_TAX_PERCENTAGE; federalTaxDeduction = grossPay * FEDERAL_INCOME_TAX_PERCENTAGE; } // --------------- Setters ----------------- /// &lt;summary&gt; /// The SetEmployeeNumber method /// sets the employee number to the given integer param /// &lt;/summary&gt; /// &lt;param name="n"&gt;an integer&lt;/param&gt; public void SetEmployeeNumber(int n) { employeeNumber = n; } /// &lt;summary&gt; /// The SetEmployeeName method /// sets the employee name to the given string param /// &lt;/summary&gt; /// &lt;param name="s"&gt;a string&lt;/param&gt; public void SetEmployeeName(string s) { employeeName = s; } /// &lt;summary&gt; /// The SetEmployeeStreetAddress method /// sets the employee street address to the given param string /// &lt;/summary&gt; /// &lt;param name="s"&gt;a string&lt;/param&gt; public void SetEmployeeStreetAddress(string s) { employeeStreetAddress = s; } /// &lt;summary&gt; /// The SetEmployeeHourlyWage method /// sets the employee hourly wage to the given double param /// &lt;/summary&gt; /// &lt;param name="d"&gt;a double value&lt;/param&gt; public void SetEmployeeHourlyWage(double d) { employeeHourlyWage = d; } /// &lt;summary&gt; /// The SetEmployeeHoursWorked method /// sets the employee hours worked to a given int param /// &lt;/summary&gt; /// &lt;param name="n"&gt;an integer&lt;/param&gt; public void SetEmployeeHoursWorked(int n) { employeeHoursWorked = n; } // -------------- Getters -------------- /// &lt;summary&gt; /// The GetEmployeeNumber method /// gets the employee number of the currnt employee object /// &lt;/summary&gt; /// &lt;returns&gt;the int value, employeeNumber&lt;/returns&gt; public int GetEmployeeNumber() { return employeeNumber; } /// &lt;summary&gt; /// The GetEmployeeName method /// gets the name of the current employee object /// &lt;/summary&gt; /// &lt;returns&gt;the string, employeeName&lt;/returns&gt; public string GetEmployeeName() { return employeeName; } /// &lt;summary&gt; /// The GetEmployeeStreetAddress method /// gets the street address of the current employee object /// &lt;/summary&gt; /// &lt;returns&gt;employeeStreetAddress, a string&lt;/returns&gt; public string GetEmployeeStreetAddress() { return employeeStreetAddress; } /// &lt;summary&gt; /// The GetEmployeeHourlyWage method /// gets the value of the hourly wage for the current employee object /// &lt;/summary&gt; /// &lt;returns&gt;employeeHourlyWage, a double&lt;/returns&gt; public double GetEmployeeHourlyWage() { return employeeHourlyWage; } /// &lt;summary&gt; /// The GetEmployeeHoursWorked method /// gets the hours worked for the week of the current employee object /// &lt;/summary&gt; /// &lt;returns&gt;employeeHoursWorked, as an int&lt;/returns&gt; public int GetEmployeeHoursWorked() { return employeeHoursWorked; } // End --- Getter/Setter methods /// &lt;summary&gt; /// The CalcSalary method /// calculates the net pay of the current employee object /// &lt;/summary&gt; /// &lt;returns&gt;netPay, a double&lt;/returns&gt; private double CalcSalary() { netPay = grossPay - stateTaxDeduction - federalTaxDeduction; return netPay; } /// &lt;summary&gt; /// The ReadFromFile method /// reads in the data from a file using a given a streamreader object /// &lt;/summary&gt; /// &lt;param name="r"&gt;a streamreader object&lt;/param&gt; /// &lt;returns&gt;an Employee object&lt;/returns&gt; public static Employee ReadFromFile(StreamReader r) { string line = r.ReadLine(); if (line == null) return null; int empNumber = int.Parse(line); string empName = r.ReadLine(); string empAddress = r.ReadLine(); string[] splitWageHour = r.ReadLine().Split(); double empWage = double.Parse(splitWageHour[0]); int empHours = int.Parse(splitWageHour[1]); return new Employee(empNumber, empName, empAddress, empWage, empHours); } /// &lt;summary&gt; /// The Print method /// prints out all of the information for the current employee object, uses string formatting /// &lt;/summary&gt; /// &lt;param name="checkNum"&gt;The number of the FluffShuffle check&lt;/param&gt; public void Print(int checkNum) { string formatStr = "| {0,-45}|"; Console.WriteLine("\n\n+----------------------------------------------+"); Console.WriteLine(formatStr, "FluffShuffle Electronics"); Console.WriteLine(formatStr, string.Format("Check Number: 231{0}", checkNum)); Console.WriteLine(formatStr, string.Format("Pay To The Order Of: {0}", employeeName)); Console.WriteLine(formatStr, employeeStreetAddress); Console.WriteLine(formatStr, string.Format("In The Amount of {0:c2}", CalcSalary())); Console.WriteLine("+----------------------------------------------+"); Console.Write(this.ToString()); Console.WriteLine("+----------------------------------------------+"); } /// &lt;summary&gt; /// The ToString method /// is an override of the ToString method, it builds a string /// using string formatting, and returns the built string. It particularly builds a string containing /// all of the info for the pay stub of a sample employee check /// &lt;/summary&gt; /// &lt;returns&gt;A string&lt;/returns&gt; public override string ToString() { StringBuilder printer = new StringBuilder(); string formatStr = "| {0,-45}|\n"; printer.AppendFormat(formatStr,string.Format("Employee Number: {0}", employeeNumber)); printer.AppendFormat(formatStr,string.Format("Address: {0}", employeeStreetAddress)); printer.AppendFormat(formatStr,string.Format("Hours Worked: {0}", employeeHoursWorked)); printer.AppendFormat(formatStr,string.Format("Gross Pay: {0:c2}", grossPay)); printer.AppendFormat(formatStr,string.Format("Federal Tax Deduction: {0:c2}", federalTaxDeduction)); printer.AppendFormat(formatStr,string.Format("State Tax Deduction: {0:c2}", stateTaxDeduction)); printer.AppendFormat(formatStr,string.Format("Net Pay: {0:c2}", CalcSalary())); return printer.ToString(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload