Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

Archive for the ‘C++’ Category

My C++ projects

Visual C++ 2010 :: Error MSB8009

Posted by Circuit Negma on March 31, 2011


Created By: Hussein Nosair

Date: 3/31/2011

IDE: Visual Studio 2010

Language: Visual C++ 2010

Project Platform: x64

Windows: Windows 7

 

Error:

Error    MSB8009: .NET Framework 2.0/3.0/3.5 target the v90 platform toolset. Please make sure that Visual Studio 2008 is installed on the machine.    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets

Cause:

Platform Toolset is set to v90

Solution:

Set Platform Toolset to v100

1. Select one of your project files. This will make sure that project is selected

2. Click Project > {name.of.your.project} Properties…

3. Expand Configuration Properties

4. Click on General

5. Locate Platform Toolset option on the right hand side

6. Click on the v90

7. Click on the drop down list arrow to your right

8. Select v100

9. Click OK to exit

 

Advertisements

Posted in C++, Visual C++ 2010 | Tagged: , , | 12 Comments »

How to Increment the nominal value of the Watchdog timer of PIC16F8xx

Posted by Circuit Negma on February 22, 2008


The most obvious reason of increasing the nominal value of WDT is to accommodate the complete code execution of your firmware including the use of Interrupt service subroutines.

The WDT has a nominal time-out value of 18ms. That is, the PIC will reset/restart the firmware execution from beginning (origin) every 18ms.

The purpose of WDT is to restart the microprocessor operations incase the microprocessor stop executing instructions due to internal hardware conflicts or infinite loop within the Firmware code.

To increment the nominal value of the WDT, one must assign the prescaler of TMRO (timer zero) to WDT. This is done be setting bit 0 of OPTION_REG register (aka. PSA bit) to 1.

PSA = 1;

Next, you need to set bits 0, 1, 2 of the OPTION_REG register (aka. PS0, PS1, and PS2). To do so, you need to look at the POSTSCALER rate select bits table in the PIC manual.

Ex: In this example I am going to assign TMR0 postscaler to WDT with a ration of 1:128.

PSA = 1; // assign prescaler to WDT

PS0 = 1; // select 1:128 scaler

PS1 = 1; // select 1:128 scaler

PS2 = 1; // select 1:128 scaler

WDT output result:

WDT timer-out = nominal value * prescaler

WDT time-out = 18ms * 128

WDT time-out = 2304 ms

WDT time-out ~= 2.3 sec

Thus, the PIC will reset every 2.3 sec.

Posted in C++, Electronics | Leave a Comment »

Tax Calculator

Posted by Circuit Negma on March 20, 2006


      

/*
 *  Copyright © 1997-2003 Metrowerks Corporation.  All Rights Reserved.
 *
 *	Created By: Circuit Negma
 *
 *	Date	  : March 20, 2006
 *
 *	File	  : ch3_tax.cpp
 *
 *	Description: calculate taxes.
 */

// Declare Header Files
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
using namespace std;

	// Define Function dCheck() to check for double numbers.
	double dCheck()
	{
		bool flag;
		double i;
		 	
 		flag = cin >> i;
 
		 while (!flag)
		 {
		       cout << endl;
		       cin.clear();
		       cin.ignore(500, '\n');
		       cout << "this is not a number" << flush << endl;
		       cout << "please enter a number again: " << flush;
		       flag = cin >> i;
		       
		}
	    
	    return i;

	}


//***************************************************************
//***************************************************************
//***************** Build in Function main() ********************

int main()
{
	
	// Declare Fixed Variables
	static const int	fedinTax = 15;		// percentage
	static const double	stateTax = 3.5;		// percentage
	static const double	ssTax	 = 5.75;	// percentage
	static const double	mmTax	 = 2.75;	// percentage
	static const int	pp	 = 5;		// percentage
	static const int	hi	 = 75;		// Dollar
	
	// Declare Input Variables
	double grossAmount;
	string nameUser;
	char FirstName[100];
	char lastName[100];
	char FileName[100];
	
	// Declare Output Variables
	double FederalTax, SteTax;
	double SoSecTax, MedicareTax;
	double PensionPlan;
	double netPay;
	
	// Declare File Stream
	ofstream outData;
	
	// Get Data from user
	cout << fixed << showpoint << setprecision(2);
	cout << flush << endl;
	cout << "Please enter your FIRST name: " << flush;
	cin >> FirstName;
	cout << endl;
	cout << "Please enter your LAST name: " << flush;
	cin >> lastName;
	cout << endl;
	cout << "Please, Enter the Gross Income: " << flush;
	grossAmount = dCheck();
	
	// Creat output file
	strcpy(FileName, FirstName);
	strcat(FileName, lastName);
	strcat(FileName, ".txt");
	outData.open(FileName);

	// Print out some informations
	cout << flush << endl;
	outData << flush << endl;
	
	cout << setw(35) << left << setfill('.') << "Federal Income Tax: "
		 << " " << fedinTax << right << setw(3) << setfill(' ') << "%" << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Federal Income Tax: "
		 	<< " " << fedinTax << right << setw(3) << setfill(' ') << "%" << flush << endl;	
	
	cout << setw(35) << left << setfill('.') << "State Tax: "
		 << " " << stateTax << "%" << flush << endl;
	outData	<< setw(35) << left << setfill('.') << "State Tax: "
		 	<< " " << stateTax << "%" << flush << endl;
	 
	cout << setw(35) << left << setfill('.') << "Social Security Tax: "
		 << " " << ssTax << "%" << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Social Security Tax: "
		 	<< " " << ssTax << "%" << flush << endl;	
	
	cout << setw(35) << left << setfill('.') << "Medicare/Medicaid Tax: "
		 << right << " " << setw(4) << mmTax << "%" << flush << endl;
	outData	<< setw(35) << left << setfill('.') << "Medicare/Medicaid Tax: "
		 	<< right << " " << setw(4) << mmTax << "%" << flush << endl;
		 
	cout << setw(35) << left << setfill('.') << "Pension Plan: "
		 << " " << pp << right << setw(4) << setfill(' ') << "%" << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Pension Plan: "
		 	<< " " << pp << right << setw(4) << setfill(' ') << "%" << flush << endl;	

	cout << setw(35) << left << setfill('.') << "Health Insurance: "
		 << " $" << hi << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Health Insurance: "
		 	<< " $" << hi << flush << endl;	
	
	// Calculate the results
	FederalTax 	= fedinTax * grossAmount / 100;
	SteTax		= stateTax * grossAmount / 100;
	SoSecTax	= ssTax	   * grossAmount / 100;
	MedicareTax     = mmTax	   * grossAmount / 100;
	PensionPlan     = pp	   * grossAmount / 100;
	netPay		= grossAmount - FederalTax - SteTax - SoSecTax - MedicareTax
				  - PensionPlan - hi;
				  
	//Print out the results
	cout << flush << endl;
	outData << flush << endl;
	
	cout << FirstName << " " << lastName << flush << endl;
	outData << FirstName << " " << lastName << flush << endl;
	
	cout << setw(35) << left << setfill('.') << "Federal Tax: "
		 << " $" << right << setw(10) << setfill(' ') << FederalTax << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Federal Tax: "
		 	<< " $" << right << setw(10) << setfill(' ') << FederalTax << flush << endl;	
	
	cout << setw(35) << left << setfill('.') << "State Tax: "
		 << " $" << right << setfill(' ') << setw(10) << SteTax << flush << endl;
	outData	<< setw(35) << left << setfill('.') << "State Tax: "
		 	<< " $" << right << setfill(' ') << setw(10) << SteTax << flush << endl;
	 
	cout << setw(35) << left << setfill('.') << "Social Security Tax: "
		 << " $" << right << setfill(' ') << setw(10) << SoSecTax << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Social Security Tax: "
		 	<< " $" << right << setfill(' ') << setw(10) << SoSecTax << flush << endl;	
	
	cout << setw(35) << left << setfill('.') << "Medicare/Medicaid Tax: "
		 << " $" << right << setfill(' ') << setw(10) << MedicareTax << flush << endl;
	outData	<< setw(35) << left << setfill('.') << "Medicare/Medicaid Tax: "
		 	<< " $" << right << setfill(' ') << setw(10) << MedicareTax << flush << endl;
		 
	cout << setw(35) << left << setfill('.') << "Pension Plan: "
		 << " $" << right << setw(10) << setfill(' ') << PensionPlan << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Pension Plan: "
		 	<< " $" << right << setw(10) << setfill(' ') << PensionPlan << flush << endl;	

	cout << setw(35) << left << setfill('.') << "Health Insurance: "
		 << " $" << right << setw(10) << setfill(' ') << hi << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Health Insurance: "
		 	<< " $" << right << setw(10) << setfill(' ') << hi << flush << endl;	

	cout << setw(35) << left << setfill('.') << "Net Pay: "
		 << " $" << right << setw(10) << setfill(' ') << netPay << flush << endl;	
	outData	<< setw(35) << left << setfill('.') << "Health Insurance: "
		 	<< " $" << right << setw(10) << setfill(' ') << netPay << flush << endl;
	
	cout << endl << endl << endl;
	cout << "The above informations are saved to " << FileName << flush << endl;
	 
	outData.close();
	return 0;
}

 

Posted in C++ | Leave a Comment »

Student Grade Calculator

Posted by Circuit Negma on March 20, 2006


/*
 *  Copyright © 1997-2003 Metrowerks Corporation.  All Rights Reserved.
 *
 *	Created By: Circuit Negma
 *
 *	Date	  : March 20, 2006
 *
 *	File	  : ch3_studentid.cpp
 *
 *	Description: retrieve student data and then calculate the student average.
 */

// Declare Header Files
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;


int main()
{
	
	// Declare File Stream Variables
	ifstream inData;	// Read data from file "inData.txt"
	ofstream outData;	// Write data to file "outData.txt"
	
	// Declare input Variables
	int		gre1, gre2, gre3, gre4, gre5;
	char	stdID;
	double	avg;
	
	// Init files
	inData.open("inData.txt");
	outData.open("outData.txt");
	outData << fixed << showpoint << setprecision(2);

	cout << fixed << showpoint << setprecision(2);
	cout << "Student Grade Calculator" << flush << endl << endl;
	
	// Get the required data from the "inData.txt" file
	inData >> stdID;
	inData >> gre1 >> gre2 >> gre3 >> gre4 >> gre5;
	
	// Print out the data
	cout << "Student ID: " << stdID <<flush <<endl;
	outData << "Student ID: " << stdID <<endl;
	
	cout << "Course Marks: " << gre1 << " " << gre2 << " " << gre3
		 << " " << gre4 << " " << gre5 << flush << endl;
	outData	<< "Course Marks: " << gre1 << " " << gre2 << " " << gre3
		 	<< " " << gre4 << " " << gre5 << flush << endl;
	
	// Calculate Average
	avg = (gre1 + gre2 + gre3 + gre4 + gre5) / 5;
	
	cout << "Student Average: " << avg << flush << endl;
	outData <<"Student Average: " << avg << endl;
		 	 
	
	inData.close();
	outData.close();
	
	return 0;
}


Posted in C++ | Leave a Comment »

Save Data to a File :: Pictures

Posted by Circuit Negma on March 20, 2006


          

Posted in C++ | Leave a Comment »

Save Data to a File

Posted by Circuit Negma on March 20, 2006


/*
 *  Copyright © 1997-2003 Metrowerks Corporation.  All Rights Reserved.
 *
 *  Created By: Circuit Negma
 *
 *  Date      : March 19, 2006
 *
 *  File      : ch3_movie.cpp
 *
 *  Decription: Movie Ticket Sale and Donation to Charity -> save results
 *		to the file "prog.txt".
 *
 */

#include <iostream>
#include <iomanip>	// to use setfill(car) Function.
#include <fstream>      // to create a file and save to the file.
using namespace std;

	// Define Function iCheck() to check for integer numbers.
	int iCheck()
	{
		bool flag;
		int i;
 	
 		flag = cin >> i;
 
		 while (!flag)
		 {
		       cout << endl;
		       cin.clear();
		       cin.ignore(500, '\n');
		       cout << "this is not a number" << flush << endl;
		       cout << "please enter a number again: " << flush;
		       flag = cin >> i;
		       
		}
		
		    
	    return i;

	}
	
	// Define Function dCheck() to check for double numbers.
	double dCheck()
	{
		bool flag;
		double i;
		
 		flag = cin >> i;
 
		 while (!flag)
		 {
		       cout << endl;
		       cin.clear();
		       cin.ignore(500, '\n');
		       cout << "this is not a number" << flush << endl;
		       cout << "please enter a number again: " << flush;
		       flag = cin >> i;
		       
		}
	    
	    return i;

	}


//***************************************************************
//***************************************************************
//***************** Build in Function main() ********************

int main()
{
	// Declare input variables
	string  movieName;
	double  AdultTicketPrice, ChildTicketPrice;
	int		noOfAdultTicketSold, noOfChildTicketSold;
	int		totalnoOfTickets;
	double	percentDonation;
	double	grossAmount;
	double	amountDonated;
	double	netSaleAmount;
	
	// Declare File stream variables
	ofstream outData;      // To save data to a file you need to use the
	                       // output file stream : ofstream.
	
	// Open the File to store data
	outData.open("prog.txt", ios::app);   // Create a file called "prog.txt" 
	                                      // with the following settings
                 // ios::app --> open "prog.txt" and append data to file, if
                 // file does not exist creat a file called "prog.txt".                       
	
	// Main Program
	
	cout << fixed << showpoint << setprecision(2);	
	
	cout << setw(30) << setfill('*') << " Welcome to Movie Theater " << flush;
	cout << setw(5)	 << " " << endl;
	cout << endl;
	
	cout << "Please, Enter movie name: " << flush;
	getline(cin, movieName);
	cout << endl;
	
	cout << "Please, Enter the price of an Adult ticket: " << flush;
	AdultTicketPrice = dCheck();
	cout << endl;
	
	cout << "Please, Enter the price of an Child ticket: " << flush;
	ChildTicketPrice = dCheck();
	cout << endl;
	
	cout << "Please, Enter number of adult tickets sold: " << flush;
	noOfAdultTicketSold = iCheck();
	cout << endl;
	
	cout << "Please, Enter number of child tickets sold: " << flush;
	noOfChildTicketSold = iCheck();
	cout << endl;
	
	cout << "Please, Enter the percentage of donation: " << flush;
	percentDonation = dCheck();
	cout << endl << endl;
	
	
	// Calculations and Results
	
	totalnoOfTickets = noOfAdultTicketSold + noOfChildTicketSold;
	grossAmount		 = (AdultTicketPrice * noOfAdultTicketSold) + (ChildTicketPrice * noOfChildTicketSold);
	amountDonated	 = grossAmount * percentDonation / 100;
	netSaleAmount	 = grossAmount - amountDonated;
	
	// Print out the Results
	
	cout << "_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*" << flush << endl;
	outData	<< "_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*" << flush << endl;
	
	cout << setw(35) << left << setfill('.') << "Movie Name: " 
		 << right << " " << movieName << endl;
		 
	outData << setw(35) << left << setfill('.') << "Movie Name: " 
		 	<< right << " " << movieName << endl;
		 
	cout << setw(35) << left << "Number of Tickets Sold: "
		 << right << setfill(' ') << setw(10) << totalnoOfTickets << endl;
	
	outData	<< setw(35) << left << "Number of Tickets Sold: "
		 	<< right << setfill(' ') << setw(10) << totalnoOfTickets << endl;
		 	
	cout << setw(35) << left << setfill('.') << "Gross Amount: "
		 << right << " $" << setfill (' ') << setw(8) << grossAmount << endl;		 

	outData	<< setw(35) << left << setfill('.') << "Gross Amount: "
		 	<< right << " $" << setfill (' ') << setw(8) << grossAmount << endl;
		 	 
	cout << setw(35) << left << setfill('.') << "Percentage of Gross Amount Donated: "
		 << right << setfill (' ') << setw(9) << percentDonation << "%" << endl;

	outData	<< setw(35) << left << setfill('.') << "Percentage of Gross Amount Donated: "
		 	<< right << setfill (' ') << setw(9) << percentDonation << "%" << endl;

	cout << setw(35) << left << setfill('.') << "Amount Donated: "
		 << right << setfill(' ') << " $" << setw(8) << amountDonated << endl;

	outData	<< setw(35) << left << setfill('.') << "Amount Donated: "
		 	<< right << setfill(' ') << " $" << setw(8) << amountDonated << endl;
		  	 
	cout << setw(35) << left << setfill('.') << "Net Sale: "
		 << right << setfill(' ') << " $" << setw(8) << netSaleAmount << endl;

	outData	<< setw(35) << left << setfill('.') << "Net Sale: "
		 	<< right << setfill(' ') << " $" << setw(8) << netSaleAmount << endl;
 
	outData.close(); // Close "prog.txt" before end program	
	return 0;
}

Posted in C++ | Leave a Comment »

Movie Calculator

Posted by Circuit Negma on March 17, 2006


/*
 *  Copyright © 1997-2003 Metrowerks Corporation.  All Rights Reserved.
 *
 *  Created By: Circuit Negma
 *
 *  Date      : March 17, 2006
 *
 *  File      : ch3_movie.cpp
 *
 *  Decription: Movie Ticket Sale and Donation to Charity.
 *
 */

#include <iostream>
#include <iomanip>	// to use setfill(car) Function.
using namespace std;

	// Define Function iCheck() to check for integer numbers.
	int iCheck()
	{
		bool flag;
		int i;
		
	//	cin.clear();
 	//	cin.ignore(500, '\n');
 	
 		flag = cin >> i;
 
		 while (!flag)
		 {
		       cout << endl;
		       cin.clear();
		       cin.ignore(500, '\n');
		       cout << "this is not a number" << flush << endl;
		       cout << "please enter a number again: " << flush;
		       flag = cin >> i;
		       
		}
		
		    
	    return i;

	}
	
	// Define Function dCheck() to check for double numbers.
	double dCheck()
	{
		bool flag;
		double i;
		
	//	cin.clear();
 	//	cin.ignore(500, '\n');
 	
 		flag = cin >> i;
 
		 while (!flag)
		 {
		       cout << endl;
		       cin.clear();
		       cin.ignore(500, '\n');
		       cout << "this is not a number" << flush << endl;
		       cout << "please enter a number again: " << flush;
		       flag = cin >> i;
		       
		}
	    
	    return i;

	}


//***************************************************************

//***************************************************************
//***************** Build in Function main() ********************

int main()
{
	// Declare input variables
	string  movieName;
	double  AdultTicketPrice, ChildTicketPrice;
	int		noOfAdultTicketSold, noOfChildTicketSold;
	int		totalnoOfTickets;
	double	percentDonation;
	double	grossAmount;
	double	amountDonated;
	double	netSaleAmount;
	
	
	// Main Program
	
	cout << fixed << showpoint << setprecision(2);	
	
	cout << setw(30) << setfill('*') << " Welcome to Movie Theater " << flush;
	cout << setw(5)	 << " " << endl;
	cout << endl;
	
	cout << "Please, Enter movie name: " << flush;
	getline(cin, movieName);
	cout << endl;
	
	cout << "Please, Enter the price of an Adult ticket: " << flush;
	AdultTicketPrice = dCheck();
	cout << endl;
	
	cout << "Please, Enter the price of an Child ticket: " << flush;
	ChildTicketPrice = dCheck();
	cout << endl;
	
	cout << "Please, Enter number of adult tickets sold: " << flush;
	noOfAdultTicketSold = iCheck();
	cout << endl;
	
	cout << "Please, Enter number of child tickets sold: " << flush;
	noOfChildTicketSold = iCheck();
	cout << endl;
	
	cout << "Please, Enter the percentage of donation: " << flush;
	percentDonation = dCheck();
	cout << endl << endl;
	
	
	// Calculations and Results
	
	totalnoOfTickets = noOfAdultTicketSold + noOfChildTicketSold;
	grossAmount		 = (AdultTicketPrice * noOfAdultTicketSold) + (ChildTicketPrice * noOfChildTicketSold);
	amountDonated	 = grossAmount * percentDonation / 100;
	netSaleAmount	 = grossAmount - amountDonated;
	
	// Print out the Results
	
	cout << "_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*" << flush << endl;
	cout << left;
	
	cout << setw(35) << setfill('.') << "Movie Name: " 
		 << right << " " << movieName << endl;
	
	cout << setw(35) << left << "Number of Tickets Sold: "
		 << right << setfill(' ') << setw(10) << totalnoOfTickets << endl;
	
	cout << setw(35) << left << setfill('.') << "Gross Amount: "
		 << right << " $" << setfill (' ') << setw(8) << grossAmount << endl;
		 
	cout << setw(35) << left << setfill('.') << "Percentage of Gross Amount Donated: "
		 << right << setfill (' ') << setw(9) << percentDonation << "%" << endl;
		 
	cout << setw(35) << left << setfill('.') << "Amount Donated: "
		 << right << setfill(' ') << " $" << setw(8) << amountDonated << endl;
		 
	cout << setw(35) << left << setfill('.') << "Net Sale: "
		 << right << setfill(' ') << " $" << setw(8) << netSaleAmount << endl;
		
	return 0;
}

Posted in C++ | Leave a Comment »