Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include // input output stream header file #include // standard input output he

ID: 3768482 • Letter: #

Question

#include // input output stream header file #include // standard input output header file #include // standard library header file #include // header file with string function #include // console input output header file using namespace std; class Name { private: char *str1; // String data member public: char *firstName, *lastName, *fullName; Name() { } // default constructor void accessor() { cout << " First Name: " << firstName; cout << " Last Name: " << lastName; } // end accessor void mutator(char *fnm, char *lnm) { strcpy(firstName, fnm); strcpy(lastName, lnm); strcpy(fullName, fnm); strcat(fullName, lnm); cout << endl << fullName << endl; } // end mutator }; // end class Name class File { public: char *ipFileName; char *opFileName; char *ipOpFileName; } ; // end class File int main() // start main { system("cls"); FILE *fnmfp, *lnmfp, *fullNmfp; // instantiate objects: Name objName; // = new Name(); fnmfp = fopen("E:/Files/fnmfile.txt", "a+"); lnmfp = fopen("E:/Files/lnmfile.txt", "a+"); fullNmfp = fopen("E:/Files/fullnm.txt", "a+"); { char*fnm, *lnm, *fullNm; cout << " Enter first name: "; getline(cin,fnm); cout << " Enter last name: "; getline(cin,lnm); strcpy(fullNm, fnm); strcat(fullNm, lnm); } fprintf(fnmfp, fnm); fprintf(lnmfp, lnm); fprintf(fullNmfp, fullNm); objName.mutator(fnm, lnm); fclose(fnmfp); fclose(lnmfp); fclose(fullNmfp); return 0; // exit } // end of main()

I am having trouble with this program, 'fnm', 'lnm' and 'fullNm' come up as undeclared characters. thanks in advance for help.

Explanation / Answer

//Let me know if there is anymore clarification

#include <iostream>// input output stream header file
#include <fstream>// standard input output header file
#include <stdlib.h>// header file with string function
#include <string>// console input output header file
#include <bits/stdc++.h> //universally includes everything

using namespace std;
class Name
{
   private:
       char *str1; // String data member
   public:
       char firstName[100], lastName[100], fullName[100];
       Name() { } // default constructor
       void accessor()
       {
           cout << " First Name: " << firstName;
           cout << " Last Name: " << lastName;
       } // end accessor

       void mutator(char *fnm, char *lnm)
       {
           strcpy(firstName, fnm);
           strcpy(lastName, lnm);
           strcpy(fullName, fnm);
           strcat(fullName, lnm);
           cout << endl << fullName << endl;
       } // end mutator
}; // end class Name

class File
{
   public:
       char *ipFileName;
       char *opFileName;
       char *ipOpFileName;
} ; // end class File

int main() // start main
{
   system("cls");
   FILE *fnmfp, *lnmfp, *fullNmfp; // instantiate objects:
   Name objName; // = new Name();
   fnmfp = fopen("E:/Files/fnmfile.txt", "a+");
   lnmfp = fopen("E:/Files/lnmfile.txt", "a+");
   fullNmfp = fopen("E:/Files/fullnm.txt", "a+");
  
   /*
   char *fnm is wrong because this is just a pointer, not pointing to any memory location
   hence you have to statically assign a memory space like I did here or you have to do dynamically

   syntax of getline was wrong

   rest are corrected
   */
   char fnm[100], lnm[100], fullNm[100];

   cout << "Enter first name: ";
   cin.getline(fnm,100);
   cout << "Enter last name: ";
   cin.getline(lnm,100);
   strcpy(fullNm, fnm);
   strcat(fullNm, lnm);

   fprintf(fnmfp, fnm);
   fprintf(lnmfp, lnm);
   fprintf(fullNmfp, fullNm);
  
   objName.mutator(fnm, lnm);
   fclose(fnmfp);
   fclose(lnmfp);
   fclose(fullNmfp);
   return 0; // exit
  
} // end of main()