c++, I am having trouble getting my program to compile, any help would be appreciated.
#include <iostream>
#include <string>
#include <string.h>
#include <fstream>
#include <stdlib.h>
using namespace std;
struct record
{
char artist[50];
char title[50];
char year[50];
};
class CD
{
//private members declared
private:
string artist; //asks for string
string title; // asks for string
int yearReleased; //asks for integer
//public members declared
public:
CD();
CD(string,string,int);
void setArtist(string);
void setTitle(string);
void setYearReleased(int);
string getArtist() const;
string getTitle() const;
int getYearReleased() const;
};
CD::CD() : artist(""),title(""), yearReleased(0)
{}
CD::CD(string artist, string title, int yearReleased): artist(artist),title(title),yearReleased(yearReleased)
{}
void CD::setArtist(string artist)
//implicit paramater, qualify the name of the class members and make it visible again.
{
this->artist = artist;
}
void CD::setTitle( string title)
{
this->title = title;
}
void CD::setYearReleased(int yearReleased)
{
this->yearReleased = yearReleased;
}
string CD::getArtist() const
{
return artist;
}
string CD::getTitle() const
{
return title;
}
int CD::getYearReleased() const
{
return yearReleased;
}
void printMenu();
void displayTestCD();
void mathBreak();
void evenOdd();
void primeNumber();
bool isPrime(int);
bool isEven(int);
void readCollection();
void displayCollection();
int main()
{
int choice;
choice =0;
while(choice != 3)
{
//The menu and the lets the user input which menu they want to access, given the option between displaying the testCD, math break or quiting. if anything else is picked, invalid choie is displayed.
printMenu();
cin>>choice; //user input
switch(choice) //switch to give the menu different option
{
case 1: // display the testCD
readCollection();
break;
case 2:
displayCollection();
break;
case 3:
displayTestCD();
break;
case 4:
break;
case 5:
break;
case 6:
mathBreak();
break;
case 7:
break;
default: // if anything other than 1-3 is chosen, display invalid choice
cout<<"Invalid choice"<
}
}
return 0;
}
//void function for the menu and the cout statements for what will be displayed when the printMenu() function is accessed
// Records array.....
struct record rc[18];
ifstream ptr;
ptr.open("cd.txt");
if(!ptr)
{
cout<<"\nFile opening error\n";
exit(1);
}
void printMenu()
{
cout<<"1.Read Collection<<endl;
cout<<"2. Display Collection"<<endl;
cout<<"3. Sort Collection"<<endl;
cout<<"4. Find a CD"<<endl;
cout<<"5. Edit CD"<<endl;
cout<<"6. Math Break"<<endl;
cout<<"7. Quit"<<endl;
}
void displayTestCD()
{
//test CD
CD cd1;
cd1.setArtist("asdfa");
cd1.setTitle("adfasdf");
cd1.setYearReleased(2019);
cout<<" Artist : "<<endl;
cout<<" Title : "<<endl;
cout<<" Year Released : "<<endl;
}
void mathBreak()
{
int subChoice;
cout << endl << "1. Even or Odd" << endl;
cout << "2. Prime Number" << endl;
cout << "3. End my Math Break" << endl;
cout << "Enter your choice: ";
cin >> subChoice;
//anything other than 1,2,3 is invalid and will prompt the user to enter a valid choice
while(subChoice < 1 || subChoice > 3)
{
cout << "Invalid choice." << endl;
cout << "Enter your choice: ";
cin >> subChoice;
}
switch(subChoice)
{
case 1:
//call the evenOdd function
evenOdd();
break;
case 2:
//call the primeNumber function
primeNumber();
break;
}
}
//Was not sure if i had to include the Math Break menu from lab 1, left it out. What I belive we are supposed to do is bring all the labs together at the end of the semester?
void evenOdd()
{
int number;
bool repeat = true;
do
{
//allow the user to input a number 0 or larger
cout << endl << "Enter an integer larger than 0:";
cout << endl <<"Enter 0 to access the previous menu. ";
cin >> number;
//repeat until a valid numebr is given
while(number < 0)
{
//if invalid numbers are input, then reprompt the user to enter a valid number
cout << "Invalid number. Negative numbers are not allowed." << endl;
cout << "Enter an integer larger than 0: ";
cin >> number;
}
//set repeat to false if 0 is entered to return to the sub menu
if(number == 0)
repeat = false;
else
{
//check and print wherther the number is even or not
if(isEven(number))
cout << "The number is even." << endl;
else
cout << "The number is odd." << endl;
}
}while(repeat);
}
bool isEven(int number)
{
//check and return whether the number is even or not
if(number % 2 == 0)
return true;
else
return false;
}
void primeNumber()
{
int number;
bool repeat = true;
do
{
cout << endl <<"Enter an integer larger than 0: ";
cout << endl <<"Enter 0 to access the previous menu. ";
cin >> number;
//if the number is less than 0 then ask for a valid number
while(number < 0)
{
cout << "Invalid number. Negative numbers are not allowed." << endl;
cout << "Enter an integer larger than 0: ";
cin >> number;
}
if(number == 0)
repeat = false;
else
{
//check and print whether the number is prime or not
if(isPrime(number))
cout << "The number is prime." << endl;
else
cout << "The number is not a prime." << endl;
}
}while(repeat);
}
bool isPrime(int number)
{
int i;
bool prime = true;
//equation to check if number is prime or not
for(i = 2; i <= number/2; ++i)
{
//if number is not prime
if(number % i == 0)
prime = false;
}
return prime;
}
void readCollection()
{
for(int i=1;i<18;i++)
{
ptr.clear();
ptr.getline(rc[i].artist, 50);
ptr.clear();
ptr.getline(rc[i].title, 50);
ptr.clear();
ptr.getline(rc[i].year, 50);
}
}
void displayCollection()
{
cout<<"Artist.........Title......Year!\n\n";
for(int i=1;i<18;i++)
{
cout<
}
ptr.close();
}
#include <iostream>
#include <string.h>
#include <fstream>
#include <stdlib.h>
using namespace std;
ifstream ptr;
struct record
{
char artist[50];
char title[50];
char year[50];
};
class CD
{
//private members declared
private:
string artist; //asks for string
string title; // asks for string
int yearReleased; //asks for integer
//public members declared
public:
CD();
CD(string,string,int);
void setArtist(string);
void setTitle(string);
void setYearReleased(int);
string getArtist() const;
string getTitle() const;
int getYearReleased() const;
};
CD::CD() : artist(""),title(""), yearReleased(0)
{}
CD::CD(string artist, string title, int yearReleased): artist(artist),title(title),yearReleased(yearReleased)
{}
void CD::setArtist(string artist)
//implicit paramater, qualify the name of the class members and make it visible again.
{
this->artist = artist;
}
void CD::setTitle( string title)
{
this->title = title;
}
void CD::setYearReleased(int yearReleased)
{
this->yearReleased = yearReleased;
}
string CD::getArtist() const
{
return artist;
}
string CD::getTitle() const
{
return title;
}
int CD::getYearReleased() const
{
return yearReleased;
}
void printMenu();
void displayTestCD();
void mathBreak();
void evenOdd();
void primeNumber();
bool isPrime(int);
bool isEven(int);
void readCollection();
void displayCollection();
int main()
{
int choice;
ptr.open("cd.txt");
if(!ptr)
{
cout<<"\nFile opening error\n";
exit(1);
}
choice =0;
while(choice != 3)
{
//The menu and the lets the user input which menu they want to access, given the option between displaying the testCD, math break or quiting. if anything else is picked, invalid choie is displayed.
printMenu();
cin>>choice; //user input
switch(choice) //switch to give the menu different option
{
case 1: // display the testCD
readCollection();
break;
case 2:
displayCollection();
break;
case 3:
displayTestCD();
break;
case 4:
break;
case 5:
break;
case 6:
mathBreak();
break;
case 7:
break;
default: // if anything other than 1-3 is chosen, display invalid choice
cout<<"Invalid choice";
}
}
return 0;
}
//void function for the menu and the cout statements for what will be displayed when the printMenu() function is accessed
// Records array.....
struct record rc[18];
void printMenu()
{
cout<<"1.Read Collection"<<endl;
cout<<"2. Display Collection"<<endl;
cout<<"3. Sort Collection"<<endl;
cout<<"4. Find a CD"<<endl;
cout<<"5. Edit CD"<<endl;
cout<<"6. Math Break"<<endl;
cout<<"7. Quit"<<endl;
}
void displayTestCD()
{
//test CD
CD cd1;
cd1.setArtist("asdfa");
cd1.setTitle("adfasdf");
cd1.setYearReleased(2019);
cout<<" Artist : "<<endl;
cout<<" Title : "<<endl;
cout<<" Year Released : "<<endl;
}
void mathBreak()
{
int subChoice;
cout << endl << "1. Even or Odd" << endl;
cout << "2. Prime Number" << endl;
cout << "3. End my Math Break" << endl;
cout << "Enter your choice: ";
cin >> subChoice;
//anything other than 1,2,3 is invalid and will prompt the user to enter a valid choice
while(subChoice < 1 || subChoice > 3)
{
cout << "Invalid choice." << endl;
cout << "Enter your choice: ";
cin >> subChoice;
}
switch(subChoice)
{
case 1:
//call the evenOdd function
evenOdd();
break;
case 2:
//call the primeNumber function
primeNumber();
break;
}
}
//Was not sure if i had to include the Math Break menu from lab 1, left it out. What I belive we are supposed to do is bring all the labs together at the end of the semester?
void evenOdd()
{
int number;
bool repeat = true;
do
{
//allow the user to input a number 0 or larger
cout << endl << "Enter an integer larger than 0:";
cout << endl <<"Enter 0 to access the previous menu. ";
cin >> number;
//repeat until a valid numebr is given
while(number < 0)
{
//if invalid numbers are input, then reprompt the user to enter a valid number
cout << "Invalid number. Negative numbers are not allowed." << endl;
cout << "Enter an integer larger than 0: ";
cin >> number;
}
//set repeat to false if 0 is entered to return to the sub menu
if(number == 0)
repeat = false;
else
{
//check and print wherther the number is even or not
if(isEven(number))
cout << "The number is even." << endl;
else
cout << "The number is odd." << endl;
}
}while(repeat);
}
bool isEven(int number)
{
//check and return whether the number is even or not
if(number % 2 == 0)
return true;
else
return false;
}
void primeNumber()
{
int number;
bool repeat = true;
do
{
cout << endl <<"Enter an integer larger than 0: ";
cout << endl <<"Enter 0 to access the previous menu. ";
cin >> number;
//if the number is less than 0 then ask for a valid number
while(number < 0)
{
cout << "Invalid number. Negative numbers are not allowed." << endl;
cout << "Enter an integer larger than 0: ";
cin >> number;
}
if(number == 0)
repeat = false;
else
{
//check and print whether the number is prime or not
if(isPrime(number))
cout << "The number is prime." << endl;
else
cout << "The number is not a prime." << endl;
}
}while(repeat);
}
bool isPrime(int number)
{
int i;
bool prime = true;
//equation to check if number is prime or not
for(i = 2; i <= number/2; ++i)
{
//if number is not prime
if(number % i == 0)
prime = false;
}
return prime;
}
void readCollection()
{
for(int i=1;i<18;i++)
{
ptr.clear();
ptr.getline(rc[i].artist, 50);
ptr.clear();
ptr.getline(rc[i].title, 50);
ptr.clear();
ptr.getline(rc[i].year, 50);
}
}
void displayCollection()
{
cout<<"Artist.........Title......Year!\n\n";
for(int i=1;i<18;i++)
{
cout<<"";
}
ptr.close();
}
The compile time errors are removed the code compiles successfully now test with your files.
c++, I am having trouble getting my program to compile, any help would be appreciated. #include...
C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...
my program wont run on my computer and im not understanding why. please help. #include<iostream> #include<iomanip> #include<string> #include "bookdata.h" #include "bookinfo.h" #include "invmenu.h" #include "reports.h" #include "cashier.h" using namespace std; const int ARRAYNUM = 20; BookData bookdata[ARRAYNUM]; int main () { bool userChoice = false; while(userChoice == false) { int userInput = 0; bool trueFalse = false; cout << "\n" << setw(45) << "Serendipity Booksellers\n" << setw(39) << "Main Menu\n\n" << "1.Cashier Module\n" << "2.Inventory Database Module\n" << "3.Report Module\n"...
fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str; while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title); getline(inFile, books[size].Author); getline(inFile, books[size].publisher); getline(inFile,...
I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...
Hello i am having a bit of trouble with a verified exit for my program. For some reason when trying to exit it loops to the team selection function? C++ Visual Studio 2017 #include "cPlayer.h" char chChoice1 = ' '; char chChoice3 = ' '; cPlayer::cPlayer() { } cPlayer::~cPlayer() { } void cPlayer::fMenu() { char chChoice3 = ' '; do { cout << "\n\t--Menu--" << endl; cout << "1) Enter Player Name" <<...
CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...
I keep getting errors and i am so confused can someone please help and show the input and output ive tried so many times cant seem to get it. main.cpp #include <iostream> #include <vector> #include <string> #include "functions.h" int main() { char option; vector<movie> movies; while (true) { printMenu(); cin >> option; cin.ignore(); switch (option) { case 'A': { string nm; int year; string genre; cout << "Movie Name: "; getline(cin, nm); cout << "Year: "; cin >> year; cout << "Genre: "; cin >> genre; //call you addMovie() here addMovie(nm, year, genre, &movies); cout << "Added " << nm << " to the catalog" << endl; break; } case 'R': { string mn; cout << "Movie Name:"; getline(cin, mn); bool found; //call you removeMovie() here found = removeMovie(mn, &movies); if (found == false) cout << "Cannot find " << mn << endl; else cout << "Removed " << mn << " from catalog" << endl; break; } case 'O': { string mn; cout << "Movie Name: "; getline(cin, mn); cout << endl; //call you movieInfo function here movieInfo(mn, movies); break; } case 'C': { cout << "There are " << movies.size() << " movies in the catalog" << endl; // Call the printCatalog function here printCatalog(movies); break; } case 'F': { string inputFile; bool isOpen; cin >> inputFile; cout << "Reading catalog info from " << inputFile << endl; //call you readFromFile() in here isOpen = readFile(inputFile, &movies); if (isOpen == false) cout << "File not found" << endl;...
The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...
I am trying to run this program in Visual Studio 2017. I keep getting this build error: error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". 1>Done building project "ConsoleApplication2.vcxproj" -- FAILED. #include <iostream> #include<cstdlib> #include<fstream> #include<string> using namespace std; void showChoices() { cout << "\nMAIN MENU" << endl; cout << "1: Addition...
C++ programming I need at least three test cases for the program and at least one test has to pass #include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; void temperatureCoverter(float cel){ float f = ((cel*9.0)/5.0)+32; cout <<cel<<"C is equivalent to "<<round(f)<<"F"<<endl; } void distanceConverter(float km){ float miles = km * 0.6; cout<<km<<" km is equivalent to "<<fixed<<setprecision(2)<<miles<<" miles"<<endl; } void weightConverter(float kg){ float pounds=kg*2.2; cout<<kg<<" kg is equivalent to "<<fixed<<setprecision(1)<<pounds<<" pounds"<<endl; } int main() { string country;...