Answers for "c++"

0

c++

// Your First C++ Program

#include <iostream>

int main() {
    std::cout << "Hello World!";
    return 0;
}
Posted by: Guest on November-30-2020
3

C++

Better than my grades
Posted by: Guest on October-13-2020
1

c++

#ifndef POLYNOMIAL_H_
#define POLYNOMIAL_H_

#include <iostream>
#include <math.h>  // fabs, pow

#include "vector_t.h"
#include "sparse_vector_t.h"

// Clase para polinomios basados en vectores densos de doubles
class Polynomial : public vector_t<double> {
 public:
  // constructores
  Polynomial(const int n = 0) : vector_t<double>(n) {};
  Polynomial(const Polynomial& pol)
      : vector_t<double>(pol) {}; // constructor de copia

  // destructor
  ~Polynomial() {};

  // E/S
  void Write(std::ostream& = std::cout, const double eps = EPS) const;
  
  // operaciones
  double Eval(const double) const;
  bool IsEqual(const Polynomial&, const double = EPS) const;
 };


// Clase para polinomios basados en vectores dispersos
class SparsePolynomial : public sparse_vector_t {
 public:
  // constructores
  SparsePolynomial(const int n = 0) : sparse_vector_t(n) {};
  SparsePolynomial(const Polynomial& pol) : sparse_vector_t(pol) {};
  SparsePolynomial(const SparsePolynomial&);  // constructor de copia

  // destructor
  ~SparsePolynomial() {};

  // E/S
  void Write(std::ostream& = std::cout) const;
  
  // operaciones
  double Eval(const double) const;
  bool IsEqual(const SparsePolynomial&, const double = EPS) const;
  bool IsEqual(const Polynomial&, const double = EPS) const;
};

// E/S
void Polynomial::Write(std::ostream& os, const double eps) const {
  os << get_size() << ": [ ";
  bool first{true};
  for (int i{0}; i < get_size(); i++)
    if (IsNotZero(at(i), eps)) {
      os << (!first ? " + " : "") << at(i)
	 << (i > 1 ? " x^" : (i == 1) ? " x" : "");
      if (i > 1)
	os << i;
      first = false;
    }
  os << " ]" << std::endl;
}

std::ostream& operator<<(std::ostream& os, const Polynomial& p) {
  p.Write(os);
  return os;
}

// Operaciones con polinomios

// Evaluación de un polinomio representado por vector denso
double Polynomial::Eval(const double x) const {
  double result{0.0};
  // poner el código aquí
  return result;
}

// Comparación si son iguales dos polinomios representados por vectores densos
bool Polynomial::IsEqual(const Polynomial& pol, const double eps) const {
  bool differents = false;
  // poner el código aquí
  return !differents;
}

// constructor de copia
SparsePolynomial::SparsePolynomial(const SparsePolynomial& spol) {
  *this = spol;   // se invoca directamente al operator=
}

// E/S
void SparsePolynomial::Write(std::ostream& os) const {
  os << get_n() << "(" << get_nz() << "): [ ";
  bool first{true};
  for (int i{0}; i < get_nz(); i++) {
    int inx{at(i).get_inx()};
    os << (!first ? " + " : "") << at(i).get_val()
       << (inx > 1 ? " x^" : (inx == 1) ? " x" : "");
    if (inx > 1)
      os << inx;
    first = false;
  }
  os << " ]" << std::endl;
}

std::ostream& operator<<(std::ostream& os, const SparsePolynomial& p) {
  p.Write(os);
  return os;
}

// Operaciones con polinomios

// Evaluación de un polinomio representado por vector disperso
double SparsePolynomial::Eval(const double x) const {
  double result{0.0};
  // poner el código aquí
  return result;
}

// Comparación si son iguales dos polinomios representados por vectores dispersos
bool SparsePolynomial::IsEqual(const SparsePolynomial& spol
			       , const double eps) const {
  bool differents = false;
  // poner el código aquí
  return !differents;
}

// Comparación si son iguales dos polinomios representados por
// vector disperso y vector denso
bool SparsePolynomial::IsEqual(const Polynomial& pol, const double eps) const {
  bool differents = false;
  // poner el código aquí
  return !differents;
}


#endif  // POLYNOMIAL_H_
Posted by: Guest on March-22-2021
1

c++

assert((std::is_same_v<int, int>))
Posted by: Guest on April-15-2021
0

c++

#include <bits/stdc++.h>
using namespace std;
	
int main() {
	
	return 0;
}
Posted by: Guest on December-03-2020
6

C++

C++ is a general-purpose programming language created by Bjarne 
Stroustrup as an extension of the C programming language, or 
"C with Classes".

//as you can also see to your right ---------------------->

C++ still qualifies as a high-level languge, yet the rise of 
languages like Ruby and Java have given capabilities that sway
people's opinion towards what is and is not "high-level". 

Yet high-level simply means it's farther from machine code and closer 
to human-readable form. Hence the need for a compiler/interpreter.

So don't get too worked up about granular specifics.
Posted by: Guest on May-20-2020
6

c++

C++ is a high-level, general-purpose programming language.

//totally not right there ----------------------------------->
Posted by: Guest on March-21-2020
1

c++

#include <iostream>

int main() {
	std::cout << "Hello, world!" << std::endl;
	return 0;
}
Posted by: Guest on July-16-2020
1

c++

God's language
Posted by: Guest on October-20-2020
0

c++

#include<iostream>#include<fstream>#include<iomanip>using namespace std;// the class that stores dataclass student{int rollno;char name[50];int eng_marks, math_marks, sci_marks, lang2_marks, cs_marks;double average;char grade;public:void getdata();void showdata() const;void calculate();int retrollno() const;}; //class ends herevoid student::calculate(){average=(eng_marks+math_marks+sci_marks+lang2_marks+cs_marks)/5.0;if(average>=90)grade='A';else if(average>=75)grade='B';else if(average>=50)grade='C';elsegrade='F';}void student::getdata(){cout<<"\nEnter student's roll number: ";cin>>rollno;cout<<"\n\nEnter student name: ";cin.ignore();cin.getline(name,50);cout<<"\nAll marks should be out of 100";cout<<"\nEnter marks in English: ";cin>>eng_marks;cout<<"\nEnter marks in Math:  ";cin>>math_marks;cout<<"\nEnter marks in Science:  ";cin>>sci_marks;cout<<"\nEnter marks in 2nd language:  ";cin>>lang2_marks;cout<<"\nEnter marks in Computer science:  ";cin>>cs_marks;calculate();}void student::showdata() const{cout<<"\nRoll number of student : "<<rollno;cout<<"\nName of student : "<<name;cout<<"\nEnglish : "<<eng_marks;cout<<"\nMaths : "<<math_marks;cout<<"\nScience : "<<sci_marks;cout<<"\nLanguage2 : "<<lang2_marks;cout<<"\nComputer Science :"<<cs_marks;cout<<"\nAverage Marks :"<<average;cout<<"\nGrade of student is :"<<grade;}int  student::retrollno() const{return rollno;}//function declarationvoid create_student();void display_sp(int);//display particular recordvoid display_all(); // display all recordsvoid delete_student(int);//delete particular recordvoid change_student(int);//edit particular record//MAINint main(){char ch;cout<<setprecision(2); do{char ch;int num;system("cls");cout<<"\n\n\n\tMENU";cout<<"\n\n\t1.Create student record";cout<<"\n\n\t2. Search student record";cout<<"\n\n\t3. Display all students records ";cout<<"\n\n\t4.Delete student record";cout<<"\n\n\t5.Modify student record";cout<<"\n\n\t6.Exit";cout<<"\n\n\What is your Choice (1/2/3/4/5/6) ";cin>>ch;system("cls");switch(ch){case '1': create_student(); break;case '2': cout<<"\n\n\tEnter The roll number "; cin>>num;display_sp(num); break;case '3': display_all(); break;case '4': cout<<"\n\n\tEnter The roll number: "; cin>>num;delete_student(num);break;case '5': cout<<"\n\n\tEnter The roll number "; cin>>num;change_student(num);break;case '6': cout<<"Exiting, Thank you!";exit(0);}}while(ch!='6');return 0;}//write student details to filevoid create_student(){student stud;ofstream oFile;oFile.open("student.dat",ios::binary|ios::app);stud.getdata();oFile.write(reinterpret_cast<char *> (&stud), sizeof(student));oFile.close();     cout<<"\n\nStudent record Has Been Created ";cin.ignore();cin.get();}// read file recordsvoid display_all(){student stud;ifstream inFile;inFile.open("student.dat",ios::binary);if(!inFile){cout<<"File could not be opened !! Press any Key to exit";cin.ignore();cin.get();return;}cout<<"\n\n\n\t\tDISPLAYING ALL RECORDS\n\n";while(inFile.read(reinterpret_cast<char *> (&stud), sizeof(student))){st.showdata();cout<<"\n\n====================================\n";}inFile.close();cin.ignore();cin.get();}//read specific record based on roll numbervoid display_sp(int n){student stud;ifstream iFile;iFile.open("student.dat",ios::binary);if(!iFile){cout<<"File could not be opened... Press any Key to exit";cin.ignore();cin.get();return;}bool flag=false;while(iFile.read(reinterpret_cast<char *> (&stud), sizeof(student))){if(stud.retrollno()==n){  stud.showdata();flag=true;}}iFile.close();if(flag==false)cout<<"\n\nrecord does not exist";cin.ignore();cin.get();}// modify record for specified roll numbervoid change_student(int n){bool found=false;student stud;fstream fl;fl.open("student.dat",ios::binary|ios::in|ios::out);if(!fl){cout<<"File could not be opened. Press any Key to exit...";cin.ignore();cin.get();return;}     while(!fl.eof() && found==false){fl.read(reinterpret_cast<char *> (&stud), sizeof(student));if(stud.retrollno()==n){stud.showdata();cout<<"\n\Enter new student details:"<<endl;stud.getdata();    int pos=(-1)*static_cast<int>(sizeof(stud));    fl.seekp(pos,ios::cur);    fl.write(reinterpret_cast<char *> (&stud), sizeof(student));    cout<<"\n\n\t Record Updated";    found=true;}}File.close();if(found==false)cout<<"\n\n Record Not Found ";cin.ignore();cin.get();}//delete record with particular roll numbervoid delete_student(int n){student stud;ifstream iFile;iFile.open("student.dat",ios::binary);if(!iFile){cout<<"File could not be opened... Press any Key to exit...";cin.ignore();cin.get();return;}ofstream oFile;oFile.open("Temp.dat",ios::out);iFile.seekg(0,ios::beg);while(iFile.read(reinterpret_cast<char *> (&stud), sizeof(student))){if(stud.retrollno()!=n){oFile.write(reinterpret_cast<char *> (&stud), sizeof(student));}}oFile.close();iFile.close();remove("student.dat");rename("Temp.dat","student.dat");cout<<"\n\n\tRecord Deleted ..";cin.ignore();cin.get();}
Posted by: Guest on June-03-2021

Browse Popular Code Answers by Language