Can you tell me what is wrong and fix this code. Thanks
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
//function
void displaymenu1();
int main ( int argc, char** argv )
{
string filename;
string character;
string enter;
int menu1=4;
char repeat; // = 'Y' / 'N';
string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found;
string document[1000][6];
ifstream infile;
char s[1000];
infile.open (filename); //name of file here. plz mention Complete path if file is not at root
int counter=0;
if (!infile) //if file opened
{ cout <<"Error with opening file";
exit(0);
}
{
while(infile.eof()==0) { //get row from text file
infile>>s;
cout<<s<<" ";
}
cout<< "\n";
stringstream ss(line); //stream to other variable
ss>>fName>>Lname>>number;
document[counter][0] =fName;
document[counter][1] =Lname;
document[counter][2] =number;
counter++;
}
infile.close(); //close file
cout<<"File scan done........"<<endl;
}
else //if file not found show the below message
{
cout << "Sorry, we could not find the file." << endl;
}
int i;
do {
displaymenu1(); //display the menu
cin >> menu1;
i=0;
switch (menu1)
{
case 1:
cout <<"\n\nDisplayall";
cout<<endl;
for(int i=0;i<counter;i++){
cout<<document[i][0]<<","<<document[i][1]<<","<<document[i][2]<<endl;
}
break;
case 2:
cout << "\nSearch by fname";
cin >> fname;
cout << "Item Found";
for(int i=0;i<counter;i++){
if(fname.compare(document[i][0])==0)
cout<<document[i][0]<<"\t"<<document[i][1]<<"\t"<<document[i][2]<<endl;
}
break;
case 3:
cout << "\nSearch by Lname";
cin >> Lname;
cout << "Item Found";
for(int i=0;i<counter;i++){
if(Lname.compare(document[i][1])==0)
cout<<document[i][0]<<"\t"<<document[i][1]<<"\t"<<document[i][2]<<endl;
}
break;
case 4:
cout << "\nSearch by number";
cin >> number;
for(int i=0;i<counter;i++){
if(number.compare(document[i][2])==0)
cout<<document[i][0]<<"\t"<<document[i][1]<<"\t"<<document[i][2]<<endl;
}
break;
case 5:
return 0;
}
//calculator stuff, better to be in a separate function
cout << "\n Do you want to continue (Y/N)?\n";
cout << "You must type a 'Y' or an 'N' :";
cin >> repeat;
getline(cin, enter);
void displaymenu1(){
cout << "\n\nPlease pick one of the following Choices" << endl;
cout << "1)" << " displayall " << endl;
cout << "2)" << "search by fname" << endl;
cout << "3)" << "search by lname " << endl;
cout << "4)" << "search by number" << endl;
cout << "5)" << "to exit." << endl;
cout<<"Enter your choice : ";
}while ((repeat == 'Y') || (repeat == 'y'));
cout << "exit \n";
return 0;
}
/*We did not get the moto of the code, but we did some syntax corrections in the code.Now the code compiles fine. If the moto of code is given We can help you solve the code.
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
//function
void displaymenu1();
int main ( int argc, char** argv ) {
string filename;
string character;
string enter;
int menu1=4;
char repeat; // = 'Y' / 'N';
string fname,fName,lname,Lname,number,Number,ch,Displayall,line,search,found;
string document[1000][6];
ifstream infile;
char s[1000];
infile.open (filename); //name of file here. plz mention Complete path if file is not at root
int counter=0;
if (!infile.is_open()) //if file opened
{
cout<<"Error with opening file"<<endl;
exit(0);
}
{
while(infile.eof()==0) { //get row from text file
infile>>s;
cout<<s<<" ";
}
cout<< "\n";
stringstream ss(line); //stream to other variable
ss>>fName>>Lname>>number;
document[counter][0] =fName;
document[counter][1] =Lname;
document[counter][2] =number;
counter++;
}
infile.close(); //close file
cout<<"File scan done........"<<endl;
int i;
do {
displaymenu1(); //display the menu
cin >> menu1;
i=0;
switch (menu1) {
case 1:
cout <<"\n\nDisplayall"<<endl;
for(int i=0;i<counter;i++){
cout<<document[i][0]<<","<<document[i][1]<<","<<document[i][2]<<endl;
}
break;
case 2:
cout << "\nSearch by fname";
cin >> fname;
cout << "Item Found";
for(int i=0;i<counter;i++){
if(fname.compare(document[i][0])==0)
cout<<document[i][0]<<"\t"<<document[i][1]<<"\t"<<document[i][2]<<endl;
}
break;
case 3:
cout << "\nSearch by Lname";
cin >> Lname;
cout << "Item Found";
for(int i=0;i<counter;i++){
if(Lname.compare(document[i][1])==0)
cout<<document[i][0]<<"\t"<<document[i][1]<<"\t"<<document[i][2]<<endl;
}
break;
case 4:
cout << "\nSearch by number";
cin >> number;
for(int i=0;i<counter;i++){
if(number.compare(document[i][2])==0)
cout<<document[i][0]<<"\t"<<document[i][1]<<"\t"<<document[i][2]<<endl;
}
break;
case 5:
return 0;
}
//calculator stuff, better to be in a separate function
cout << "\n Do you want to continue (Y/N)?\n";
cout << "You must type a 'Y' or an 'N' :";
cin >> repeat;
getline(cin, enter);
}while ((repeat == 'Y') || (repeat == 'y'));
cout << "exit \n";
return 0;
}
void displaymenu1(){
cout << "\n\nPlease pick one of the following Choices" << endl;
cout << "1)" << " displayall " << endl;
cout << "2)" << "search by fname" << endl;
cout << "3)" << "search by lname " << endl;
cout << "4)" << "search by number" << endl;
cout << "5)" << "to exit." << endl;
cout<<"Enter your choice : ";
} */
//======================New Corrected Code=============================
/*Assumptions made :
file name to be input.txt
input format assumed like in below given input file
*/
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
//function
void displaymenu1();
int main ( int argc, char** argv ) {
int menu1=4;
int counter=0;
string filename = "input.txt", character, enter,
fname, fName, lname, Lname, number, Number, ch, Displayall, line,
search, found;
string document[1000][6];
ifstream infile;
char repeat; // = 'Y' / 'N';
char s[1000];
infile.open (filename); //name of file here. plz
mention Complete path if file is not at root
if (!infile.is_open()) //if file opened
{
cout << "Error with opening
file" << endl;
exit(0);
}
while(getline(infile,line)) { //get row from text
file
stringstream ss(line); //stream to
other variable
ss>>fName>>Lname>>number;
document[counter][0] =fName;
document[counter][1] =Lname;
document[counter][2] =number;
counter++;
}
infile.close(); //close file
cout << "File scan done........" <<
endl;
do {
displaymenu1(); //display the
menu
cin >> menu1;
switch (menu1) {
case 1:
{
cout << "Displayall" << endl;
for(int i=0;i<counter;i++){
cout << document[i][0]
<< "," << document[i][1] << "," <<
document[i][2] << endl;
}
break;
}
case 2:
{
cout << "Search by fname" <<
endl;
cin >> fname;
int i;
for(i=0;i<counter;i++){
if(fname.compare(document[i][0])==0){
cout
<< "Item Found" << endl;
cout
<< document[i][0] << "\t" << document[i][1]
<< "\t" << document[i][2] << endl;
break;
}
}
if (i == counter) {
cout << "Item Not
Found" << endl;
}
break;
}
case 3:
{
cout << "Search by Lname" <<
endl;
cin >> Lname;
int i;
for(i=0;i<counter;i++){
if(Lname.compare(document[i][1])==0) {
cout
<< "Item Found" << endl;
cout
<< document[i][0] << "\t" << document[i][1]
<< "\t" << document[i][2] << endl;
break;
}
}
if (i == counter) {
cout << "Item Not
Found" << endl;
}
break;
}
case 4:
{
cout << "Search by number" <<
endl;
cin >> number;
int i;
for(i=0;i<counter;i++){
if(number.compare(document[i][2])==0) {
cout
<< "Item Found" << endl;
cout
<< document[i][0] << "\t" << document[i][1]
<< "\t" << document[i][2] <<endl;
break;
}
}
if (i == counter) {
cout << "Item Not
Found" << endl;
}
break;
}
case 5:
return 0;
default :
cout << "Invalid Option" <<
endl;
return 1;
}
//calculator stuff, better to be in a separate
function
cout << "Do you want to continue (Y/N)?"
<< endl;
cout << "You must type a 'Y' or an 'N' :"
<< endl;
cin >> repeat;
getline(cin, enter);
}while ((repeat == 'Y') || (repeat == 'y'));
cout << "exit" << endl;
return 0;
}
void displaymenu1() {
cout <<endl << "Please pick one of the
following Choices" << endl;
cout << "1)" << " displayall " <<
endl;
cout << "2)" << "search by fname" <<
endl;
cout << "3)" << "search by lname "
<< endl;
cout << "4)" << "search by number"
<< endl;
cout << "5)" << "to exit." <<
endl;
cout<<"Enter your choice : "<<endl;
}
/*
=================================INPUT FILE(assumed)==================
a apple 1
b boy 2
=================================OUT PUT=========================
File scan done........
Please pick one of the following Choices
1) displayall
2)search by fname
3)search by lname
4)search by number
5)to exit.
Enter your choice :
1
Displayall
a,apple,1
b,boy,2
Do you want to continue (Y/N)?
You must type a 'Y' or an 'N' :
Y
Please pick one of the following Choices
1) displayall
2)search by fname
3)search by lname
4)search by number
5)to exit.
Enter your choice :
2
Search by fname
a
Item Found
a apple 1
Do you want to continue (Y/N)?
You must type a 'Y' or an 'N' :
Y
Please pick one of the following Choices
1) displayall
2)search by fname
3)search by lname
4)search by number
5)to exit.
Enter your choice :
3
Search by Lname
apple
Item Found
a apple 1
Do you want to continue (Y/N)?
You must type a 'Y' or an 'N' :
Y
Please pick one of the following Choices
1) displayall
2)search by fname
3)search by lname
4)search by number
5)to exit.
Enter your choice :
4
Search by number
1
Item Found
a apple 1
Do you want to continue (Y/N)?
You must type a 'Y' or an 'N' :
N
exit
=========================================================*/
Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string>...
please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...
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,...
The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...
Can sombody tell me what wrong for this code to work?? It is c++ btw. thanks! #include <iostream> #include <string> using namespace std; double op1; double op2; string ADD; string SUBTRACT; string MULTIPLY; string DIVIDE; string selection; string multiply; string divide; string add; string subtract; string "*"; string "+"; string "-"; string "/"; int main() { do { cout << "--------WELCOME TO THE CALCULATOR----------" << endl; cout << "Enter your first operand: "; cin >> op1; cout << "Enter your...
Hi there! I need to fix the errors that this code is giving me and also I neet to make it look better. thank you! #include <iostream> #include <windows.h> #include <ctime> #include <cstdio> #include <fstream> // file stream #include <string> #include <cstring> using namespace std; const int N=10000; int *freq =new int [N]; int *duration=new int [N]; char const*filename="filename.txt"; int songLength(140); char MENU(); // SHOWS USER CHOICE void execute(const char command); void About(); void Save( int freq[],int duration[],int songLength); void...
moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...
#include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...
Write a simple telephone directory program in C++ that looks up phone numbers in a file containing a list of names and phone numbers. The user should be prompted to enter a first name and last name, and the program then outputs the corresponding number, or indicates that the name isn't in the directory. After each lookup, the program should ask the user whether they want to look up another number, and then either repeat the process or exit the...
graph binary search for size and time c++ //System Libraries #include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <iomanip> #include <algorithm> using namespace std; //User Libraries //Global Constants, no Global Variables are allowed //Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc... //Function Prototypes //Execution Begins Here! int main(int argc, char** argv) { int n, i, arr[50], search, first, last, middle,count=0,count_in,tot; clock_t start, end; float duration; cout<<"Enter total number of elements :"; cin>>n; cout<<"Enter numbers"; for (i=0; i<n;i++) cin>>arr[i]; cout<<"Enter a...
In C++: Please help me correct this code .... All parts with (FIX ME) #include <algorithm> #include <climits> #include <iostream> #include <string> // atoi #include <time.h> #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ const unsigned int DEFAULT_SIZE = 179; // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() {...